加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

检查字符串是否是Postgresql的日期

发布时间:2020-12-13 16:30:09 所属栏目:百科 来源:网络整理
导读:postgresql中是否有一个函数返回boolean,无论给定的字符串是否是MSSQL的日期 ISDATE(“2014年1月1日”) 谢谢! 您可以创建一个功能: create or replace function is_date(s varchar) returns boolean as $$begin perform s::date; return true;exception wh
postgresql中是否有一个函数返回boolean,无论给定的字符串是否是MSSQL的日期

ISDATE(“2014年1月1日”)

谢谢!

您可以创建一个功能:
create or replace function is_date(s varchar) returns boolean as $$
begin
  perform s::date;
  return true;
exception when others then
  return false;
end;
$$language plpgsql;

然后,您可以像这样使用它:

postgres=# select is_date('January 1,2014');
 is_date
---------
 t
(1 row)

postgres=# select is_date('20140101');
 is_date
---------
 t
(1 row)

postgres=# select is_date('20140199');
 is_date
---------
 f
(1 row)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读