From: | Gavan Schneider <pg-gts(at)snkmail(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: BEFORE UPDATE trigger doesn't change column value |
Date: | 2013-04-05 21:54:11 |
Message-ID: | 8971-1365198852-811807@sneakemail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On 5/4/13 at 6:59 AM, Clemens Eisserer wrote:
>Sorry for this newbie-question, I am trying for quite some time now to get
>the following trigger-function to work properly:
>
>CREATE OR REPLACE FUNCTION update_synced_column()
>RETURNS trigger AS
>$BODY$
>BEGIN
>IF NEW.synced IS NULL THEN
>NEW.synced := false;
>END IF;
>RETURN NEW;
>END;
>$BODY$
>LANGUAGE plpgsql VOLATILE
>COST 100;
>
>The idea is basically to always update the "synced" column to false, unless
>a value has been provided manually in the UPDATE-clause.
>Synced is defined as BOOLEAN DEFAULT FALSE;
>I execute this function in a BEFORE UPDATE trigger FOR EACH ROW, however it
>doesn't seem to have any effect.
>
You could also add 'NOT NULL' to the declaration of synced so
this column can never be set to NULL and this would further
ensure the trigger function has nothing to do.
By way of sanity testing, do you get any rows when doing
something like:
SELECT * FROM relevant_table WHERE synced IS NULL;
>Any ideas what could be wrong here?
>
If the above does not apply and at the risk of being too obvious
(specifically not wishing to cause offence):
Has the trigger itself been declared?
refer: <http://www.postgresql.org/docs/9.2/static/sql-createtrigger.html>
Is the function ever getting called?
refer: <http://www.postgresql.org/docs/9.2/static/plpgsql-errors-and-messages.html>
Regards
Gavan Schneider
From | Date | Subject | |
---|---|---|---|
Next Message | Clemens Eisserer | 2013-04-05 22:15:27 | Re: BEFORE UPDATE trigger doesn't change column value |
Previous Message | Mike Blackwell | 2013-04-05 21:20:06 | Re: Syntax problem with INDEX on expression |