Trigger not working as expected, first row gets a null value - Mailing list pgsql-general

From novnov
Subject Trigger not working as expected, first row gets a null value
Date
Msg-id 12061101.post@talk.nabble.com
Whole thread Raw
Responses Re: Trigger not working as expected, first row gets a null value
List pgsql-general
I have a trigger function that updates a field in the update/insert table
which uses a not so simple sql statement to find the value to update with. I
am not getting the results I expect. I expect I'm falling into some classic
trigger gotcha.

The table being updated is for 'bids'; 'bids has a fkey to the parent 'item'
table.

The first time a 'bid' row is added for a particular 'item', the trigger
returns null.

Any subsequent 'bids' on an 'item' find that the trigger has been invoked
and a correct calc applied for the new rows.

If value the trigger should apply is hard coded, all table updates get the
hard coded value. So there seems to be some kind of timing issue when the
complex sql gets involved. But, why does it work after the first row is
added for the 'item'?

If I change the trigger to be invoked after insert/update, a '0' value is
always inserted...I also don't understand that.
--
View this message in context:
http://www.nabble.com/Trigger-not-working-as-expected%2C-first-row-gets-a-null-value-tf4238812.html#a12061101
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


pgsql-general by date:

Previous
From: Emi Lu
Date:
Subject: Dump all objects under a specific schema
Next
From: Aurynn Shaw
Date:
Subject: Re: Dump all objects under a specific schema