Skip site navigation (1) Skip section navigation (2)

Re: get a pkey/id back from/after an insert

From: Richard Broersma Jr <rabroersma(at)yahoo(dot)com>
To: Corey <corey(at)bitworthy(dot)net>, pgsql-novice(at)postgresql(dot)org
Subject: Re: get a pkey/id back from/after an insert
Date: 2006-06-19 22:00:53
Message-ID: 20060619220053.75915.qmail@web31802.mail.mud.yahoo.com (view raw or flat)
Thread:
Lists: pgsql-novice
> Ok, so of course, a few more minutes of searching/reading/googling, 
> and I found the answer to my own question:
> 
> currval()/nextval()

I am not sure what the best practice is for adding records to both a "parent" and "child" table. 
However, examples in the postgresql documentation demonstrate the use a view that joins the parent
and child tables.

Rules are used to propagate insert/update/delete statements on the view to the actual parent/child
tables.  In addition to this, inserts to the view can also be redirected using triggers.

Once this is setup, I would expect that it would simplify your procedural code.

See:
http://www.postgresql.org/docs/8.1/interactive/rules.html


I would be interested in seeing if there is a way to preform operations like this (without views)
with just one Sql statement.

Regards,

Richard Broersma Jr.

In response to

Responses

pgsql-novice by date

Next:From: CoreyDate: 2006-06-19 22:27:53
Subject: Re: get a pkey/id back from/after an insert
Previous:From: CoreyDate: 2006-06-19 21:18:01
Subject: Re: get a pkey/id back from/after an insert

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group