i am using this function in a trigger:
我在触发器中使用此功能:
CREATE OR REPLACE FUNCTION xx() RETURNS trigger AS $xx$
BEGIN
INSERT INTO my_log (x, y, z) VALUES (NEW.x, NEW.y, current_setting('myvar.user'));
RETURN NULL;
END;
$xx$ LANGUAGE plpgsql;
now i would like to check, if 'myvar.user' is a valid integer, and if not, do another INSERT statement.
现在我想检查一下,如果'myvar.user'是一个有效的整数,如果没有,则执行另一个INSERT语句。
how would i do this?
我该怎么做?
2 个解决方案
#1
9
SELECT current_setting('myvar.user') ~ '^[0-9]+$'
#2
2
Taken from archives.postgresql.org:
取自archives.postgresql.org:
CREATE FUNCTION isnumeric(text) RETURNS boolean AS '
SELECT $1 ~ ''^[0-9]+$''
' LANGUAGE 'sql';
#1
9
SELECT current_setting('myvar.user') ~ '^[0-9]+$'
#2
2
Taken from archives.postgresql.org:
取自archives.postgresql.org:
CREATE FUNCTION isnumeric(text) RETURNS boolean AS '
SELECT $1 ~ ''^[0-9]+$''
' LANGUAGE 'sql';