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;
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;
From the documentation:
... you can return None or "OK" from the Python function to indicate the row is unmodified, "SKIP" to abort the event, or [...] "MODIFY" to indicate you've modified the new row.
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.