Question

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.

how would i do this?

Was it helpful?

Solution

SELECT  current_setting('myvar.user') ~ '^[0-9]+$'

OTHER TIPS

Taken from archives.postgresql.org:

CREATE FUNCTION isnumeric(text) RETURNS boolean AS '
SELECT $1 ~ ''^[0-9]+$''
' LANGUAGE 'sql';
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top