Re: inserting to a multi-table view - Mailing list pgsql-general

From Michael Shulman
Subject Re: inserting to a multi-table view
Date
Msg-id c3f821000806191056o5aca6bb8rdec689127712dd5c@mail.gmail.com
Whole thread Raw
In response to Re: inserting to a multi-table view  ("Michael Shulman" <shulman@mathcamp.org>)
List pgsql-general
On Tue, Jun 17, 2008 at 10:15 AM, Michael Shulman <shulman@mathcamp.org> wrote:
> <philippe.gregoire@boreal-is.com> wrote:
>> CREATE RULE studentinro_insert AS ON INSERT TO studentinfo
>> DO INSTEAD
>> (
>> INSERT INTO person ...;
>> INSERT INTO student(person_id,...) VALUES
>> (currval('person_person_id_seq'),...);
>> );

This does, however, break if someone tries to insert more than one row
at a time.

INSERT INTO studentinfo (...) VALUES (...), (...);

produces

ERROR:  duplicate key value violates unique constraint.

I expect that what happens is that first all the inserts into person
happen, then all the inserts into student happen, and all the latter
ones try to use the same currval.

Mike

pgsql-general by date:

Previous
From: Garry Saddington
Date:
Subject: Re: Losing data
Next
From: Garry Saddington
Date:
Subject: Re: Losing data