postgres判断字符串是否为时间,数字

时间判断函数定义:

-- FUNCTION: public.isdate(character varying)

-- DROP FUNCTION public.isdate(character varying);

CREATE OR REPLACE FUNCTION public.isdate(
    datestr character varying)
    RETURNS boolean
    LANGUAGE 'plpgsql'

    COST 100
    VOLATILE 
AS $BODY$
BEGIN

IF (dateStr IS NULL) THEN
     RETURN FALSE;
END IF;
     PERFORM dateStr::timestamp;
     RETURN TRUE;
EXCEPTION
     WHEN others THEN
     RETURN FALSE;


END;
$BODY$;

数字判断函数定义:

 1 -- FUNCTION: public.isnumeric(character varying)
 2 
 3 -- DROP FUNCTION public.isnumeric(character varying);
 4 
 5 CREATE OR REPLACE FUNCTION public.isnumeric(
 6     txtstr character varying)
 7     RETURNS boolean
 8     LANGUAGE 'plpgsql'
 9 
10     COST 100
11     VOLATILE 
12 AS $BODY$ 
13 BEGIN 
14    
15 RETURN txtStr ~ '^([0-9]+[.]?[0-9]*|[.][0-9]+)$'; 
16    
17    
18 END; 
19 $BODY$;

你可能感兴趣的:(postgres判断字符串是否为时间,数字)