Re: Trigger (Transaction related)

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Harpreet Dhaliwal <harpreet(dot)dhaliwal01(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Trigger (Transaction related)
Date: 2006-09-01 07:00:17
Message-ID: 20060901070017.GD12644@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, Sep 01, 2006 at 02:51:59AM -0400, Harpreet Dhaliwal wrote:
> Hi,
> I've written a trigger after insert on a table (parser) and the trigger
> calls a function that dynamically loads a shared object written in C.
>
> This shared object intends to use the newly inserted row in the table on
> which trigger is written and insert values in another table, something like
> this,

<snip>

> Above line of code is not able to read the values of newly inserted code i.e
> SELECT contents FROM parser WHERE id = %d
> and throws an error.

The new values are in the "NEW" pseudo-tuple. See the trigger
documentation on how to access it. In the pl/sql and pl/pgsql languages
you just say "NEW.<fieldname>". Not sure about C though.

> Is it because its still the same transaction going on and the insert fired
> on parser talbe won't be reflected in the select query in the shared object
> which is a part of the same transaction???

I don't think its visible in the table yet for a BEFORE INSERT trigger.
AFTER INSERT maybe, but in either case, the NEW tuple has the actual
values.

Hope this helps,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jeroen T. Vermeulen 2006-09-01 07:02:57 GBorg down?
Previous Message Harpreet Dhaliwal 2006-09-01 06:51:59 Trigger (Transaction related)