Re: inserting to a multi-table view

From: "Michael Shulman" <shulman(at)mathcamp(dot)org>
To: "Klint Gore" <kgore4(at)une(dot)edu(dot)au>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: inserting to a multi-table view
Date: 2008-06-17 14:58:45
Message-ID: c3f821000806170758q6321b0c1h564b81d1c7ee301b@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Jun 17, 2008 at 3:46 AM, Klint Gore <kgore4(at)une(dot)edu(dot)au> wrote:
> The only way I could find to make this work is to use a rule and wrap the
> inner "insert returning" in a function.

Thanks, this works! Although it feels like something of a hack;
shouldn't there be a more elegant solution?

Also, I don't understand why

> create rule atest as on insert to studentinfo do instead (
> insert into student (person_id) select (select person_id from newperson(new));
> );

is necessary; what is wrong with

create rule atest as on insert to studentinfo do instead (
insert into student (person_id) select person_id from newperson(new);
);

? (Other than the evident fact that it doesn't work; the error
message "function expression in FROM cannot refer to other relations
of same query level" is not illuminating to me.)

Additionally, is there a reason why you put one of the inserts in the
function and the other in the rule? Why not have the function do both
inserts and then the rule just invoke the function?

Mike

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Michael Shulman 2008-06-17 15:15:23 Re: inserting to a multi-table view
Previous Message Pavel Arnošt 2008-06-17 14:55:31 Re: problem with to_ascii() function in version 8.3.3