2009-09-09 42 views
5

estoy usando esta función en un disparador:¿Cómo verificar si un valor es un número entero con plpgsql?

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; 

Ahora me gustaría comprobar si 'myvar.user' es un número entero válido, y si no, hacer otra instrucción INSERT.

¿cómo haré esto?

Respuesta

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