postgres 문자열이 시간, 숫자인지 판단

4488 단어
시간 판단 함수 정의:
-- 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$;

좋은 웹페이지 즐겨찾기