pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Stephan Szabo <sszabo@megazone23.bigpanda.com>
To: Brian <Brian@McSweeney.iol.ie>
Cc: pgsql-sql@postgresql.org
Subject: Re: INSERT question
Date: Thu, 15 Nov 2001 07:03:16 -0800 (PST)
Message-ID: <20011115070141.P7025-100000@megazone23.bigpanda.com> (raw)
In-Reply-To: <1f5f2b44.0111130130.17e8e57a@posting.google.com>


On 13 Nov 2001, Brian wrote:

> Hi everyone,
> I've a little question about using insert statements. I've got a
> parent table with a "serial" (automatically incrementing integer)
> primary key. I have a child table with a foreign key which references
> that primary key. My question is:
>
> To insert values into the child table corresponding to an entry in the
> parent table, how do I get a reference to the serial primary key (so
> as I can reference it for the foreign key entry)
>
> Hope you understand what I mean. This should be a regular occurance
> and seeing as I'm not an sql guru, I just don't have a clue!

I'd say use select currval('<sequence name generated by serial>');
Serial is really just a handy wrapper around a sequence and a column
default, so I'd suggest reading the docs on sequences.




view thread (12+ messages)  latest in thread

Message-ID: <20011115070141.P7025-100000@megazone23.bigpanda.com>
Permalink:  ../20011115070141.P7025-100000@megazone23.bigpanda.com/
Also on:    postgresql.org/message-id/20011115070141.P7025-100000@megazone23.bigpanda.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: sszabo@megazone23.bigpanda.com, Brian@McSweeney.iol.ie
  Subject: Re: INSERT question
  In-Reply-To: <20011115070141.P7025-100000@megazone23.bigpanda.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox