Re: How to insert into 2 tables from a view?

From: David G Johnston <david(dot)g(dot)johnston(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: How to insert into 2 tables from a view?
Date: 2014-12-24 02:23:28
Message-ID: CAKFQuwZnpvkuo36ea5wFiiLsmaq5EEeehqKUt+88+mU520sBPQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Dec 23, 2014 at 6:40 PM, rob stone-2 [via PostgreSQL] <
ml-node+s1045698n5831909h3(at)n5(dot)nabble(dot)com> wrote:

> Rather strange to have two tables sharing the same primary key value.
> One would have thought it was a one-to-many relationship between table1
> and table2.
>
>
​while not particularly common 1-to-1 relationships can be quite useful.
Even if not required for the data model and implementation using 1-to-1
makes sense if a subset of the model data has a change profile different
than other parts. One of the tables is basically static while the,
hopefully smaller (column count) related table has updates performed
against it. The main table does not exhibit churn for updates and does not
need the related vacuuming.

rob>>I can vaguely remember that in version 9.0 you have to use dollar
quoted
rob>>variables so the first insert would become[...]

Ppositional variable references are only required for earlier versions of
SQL functions; all supported pl/pgsql functions can make use of named
arguments.

Note you can also make use of (I think, not sure on the version
requirements):

INSERT INTO [...] RETURNING idfield INTO variable
INSERT INTO [...] VALUES (variable);

David J.

--
View this message in context: http://postgresql.nabble.com/How-to-insert-into-2-tables-from-a-view-tp5831876p5831910.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Berend Tober 2014-12-24 02:41:10 Re: How to insert into 2 tables from a view?
Previous Message rob stone 2014-12-24 01:39:09 Re: How to insert into 2 tables from a view?