Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

postgresql set default value in trigger

i have a "before update trigger" on a table. How to set default value on a column ? :

CREATE OR REPLACE FUNCTION trigger() RETURNS TRIGGER AS
$$

TD["new"]["test"] = DEFAULT # Doesn't work

$$ LANGUAGE plpython2u VOLATILE;
like image 967
fksg0001 fksg0001 Avatar asked Mar 15 '26 09:03

fksg0001 fksg0001


1 Answers

I don't think that there is a way to do that, as default values are evaluated before the triggers are called.

For simple default values (constants), you may be able to work around that by looking up pg_get_expr(adbin, adrelid) AS default_value in the corresponding entry in pg_catalog.pg_attrdef and using that, but it sure ain't a pretty solution.

like image 99
Laurenz Albe Avatar answered Mar 17 '26 03:03

Laurenz Albe