Trigger not working as expected, first row gets a null value

From: novnov <novnovice(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Trigger not working as expected, first row gets a null value
Date: 2007-08-08 20:20:33
Message-ID: 12061101.post@talk.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Kris Jurka 2007-08-08 20:21:18 Re: Dump all objects under a specific schema
Previous Message Aurynn Shaw 2007-08-08 20:20:29 Re: Dump all objects under a specific schema