检查字符串是否为日期Postgresql [英] Check whether string is a date Postgresql
本文介绍了检查字符串是否为日期Postgresql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
PostgreSQL
中是否有任何函数可以返回 Boolean
,无论给定的字符串是否是日期,就像 ISDATE()
in MSSQL?
Is there any function in PostgreSQL
that returns Boolean
whether a given string is a date or not just like ISDATE()
in MSSQL?
ISDATE("January 1, 2014")
推荐答案
您可以创建一个函数:
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;
然后,您可以像这样使用它:
Then, you can use it like this:
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)
这篇关于检查字符串是否为日期Postgresql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文