Re: Help with INSERT into 2 tables

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Gintas <gntrs(at)hotmail(dot)com>
Cc: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Help with INSERT into 2 tables
Date: 2001-11-15 15:11:04
Message-ID: 20011115070849.N7025-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


On 13 Nov 2001, Gintas wrote:

> I am new to SQL and don't know how to INSERT records to 2 tables.
>
> The first table:
>
> CREATE TABLE aaaa ( aaaaid SERIAL PRIMARY KEY,
> text VARCHAR(20)
> );
>
> Second table:
>
> CREATE TABLE bbbb ( bbbbid SERIAL PRIMARY KEY,
> aaaaid INTEGER REFERENCES aaaa (aaaaid) ON
> DELETE CASCADE,
> sometext VARCHAR(200)
> );
>
> I want to insert related records to both table. The problem is that
> in order to insert record to the second table it's necessary to know
> "aaaaid" field from the first table("text" is not UNIQUE):
>
> INSERT INTO aaaa (text) VALUES ('Some info');
> INSERT INTO bbbb (aaaaid, sometext) VALUES (?????, 'Some text');
I think you want:
currval('aaaa_aaaaid_seq')

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Jeff Eckermann 2001-11-15 15:47:17 Re: Help with INSERT into 2 tables
Previous Message Stephan Szabo 2001-11-15 15:07:47 Re: Help with RULE