Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check, if a value is an integer with plpgsql?

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?

like image 849
return1.at Avatar asked Sep 09 '09 12:09

return1.at


1 Answers

SELECT  current_setting('myvar.user') ~ '^[0-9]+$'
like image 129
Quassnoi Avatar answered Nov 09 '22 18:11

Quassnoi