Re: INSERT question

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Brian <Brian(at)McSweeney(dot)iol(dot)ie>
Cc: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: INSERT question
Date: 2001-11-15 15:03:16
Message-ID: 20011115070141.P7025-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


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.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Stephan Szabo 2001-11-15 15:07:47 Re: Help with RULE
Previous Message Martín Marqués 2001-11-15 13:57:54 Re: Unable to use '-' in column names in PLPGSQL