Re: inserting to a multi-table view

From: "Michael Shulman" <shulman(at)mathcamp(dot)org>
To: Philippe Grégoire <philippe(dot)gregoire(at)boreal-is(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: inserting to a multi-table view
Date: 2008-06-19 17:56:19
Message-ID: c3f821000806191056o5aca6bb8rdec689127712dd5c@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Jun 17, 2008 at 10:15 AM, Michael Shulman <shulman(at)mathcamp(dot)org> wrote:
> <philippe(dot)gregoire(at)boreal-is(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Geoffrey 2008-06-19 17:58:23 Re: Losing data
Previous Message Adrian Klaver 2008-06-19 17:52:06 Re: Losing data