Thread: trigger on view returning created serial

trigger on view returning created serial

From
Philipp Kraus
Date:
Hello,

I have created a view and on this view a trigger, which is called on an insert command on the view.
Within the trigger I run an insert on a table and one of the table fields uses a serial sequence, that
creates values. If I run in the trigger after the insert a "return NEW", the field (id) which should
be set by the serial on the table is 0, so how can I get the new created serial on the insert command
within the trigger function?

Thanks

Phil

Re: trigger on view returning created serial

From
Jeff Davis
Date:
On Tue, 2012-06-12 at 22:35 +0200, Philipp Kraus wrote:
> Hello,
>
> I have created a view and on this view a trigger, which is called on an insert command on the view.
> Within the trigger I run an insert on a table and one of the table fields uses a serial sequence, that
> creates values. If I run in the trigger after the insert a "return NEW", the field (id) which should
> be set by the serial on the table is 0, so how can I get the new created serial on the insert command
> within the trigger function?

It's hard for me to tell exactly what problem you're describing, but it
sounds similar to the one solved here:

http://people.planetpostgresql.org/dfetter/index.php?/archives/66-VIEW-triggers-RETURNING....html

If I misunderstood, please be more descriptive about what you are trying
to do, what code you wrote, and what went wrong.

Regards,
    Jeff Davis