Re: Trigger (Transaction related)

Поиск
Список
Период
Сортировка
От Harpreet Dhaliwal
Тема Re: Trigger (Transaction related)
Дата
Msg-id d86a77ef0609010019o193bfd95p795e9ba04c9bc3d7@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Trigger (Transaction related)  (Martijn van Oosterhout <kleptog@svana.org>)
Ответы Re: Trigger (Transaction related)  (Roman Neuhauser <neuhauser@sigpipe.cz>)
Список pgsql-general
If that is the case then why does it throw error in one on the insert queries in the shared object written in SPI without inserting the row on the table on which record is inserted.

Follwing query in the shared object throws an error.


INSERT INTO headers (id, header_content) VALUES (1, SELECT raw_email FROM parser WHERE id = 1)

Error is
ERROR:  syntax error at or near "SELECT" at character 53

Regardless the error in the shared object, why doesn't it insert the row in the table on which AFTER INSERT trigger is written?

Thanks,

~Harpreet
On 9/1/06, Martijn van Oosterhout <kleptog@svana.org> wrote:
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@svana.org>   http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFE99qBIB7bNG8LQkwRAq7KAJ4p+rTE1TYgKjpydTlb30YY0yDdFgCghDiP
Yj3c+7ayJihJ9LKYwrFYoX0=
=4W51
-----END PGP SIGNATURE-----



В списке pgsql-general по дате отправления:

Предыдущее
От: Anton de Wet
Дата:
Сообщение: Re: [pgsql-advocacy] Thought provoking piece on NetBSD
Следующее
От: Roman Neuhauser
Дата:
Сообщение: Re: Trigger (Transaction related)