pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: gntrs@hotmail.com
To: pgsql-sql@postgresql.org
Subject: Help with INSERT into 2 tables
Date: 13 Nov 2001 05:42:08 -0800
Message-ID: <558f8e45.0111130542.1e617f99@posting.google.com> (raw)

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');

How is it possible to do that?
(I am inserting this from JAVA).

Thanks for help.



Gintaras



view thread (6+ messages)  latest in thread

Message-ID: <558f8e45.0111130542.1e617f99@posting.google.com>
Permalink:  ../558f8e45.0111130542.1e617f99@posting.google.com/
Also on:    postgresql.org/message-id/558f8e45.0111130542.1e617f99@posting.google.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: gntrs@hotmail.com
  Subject: Re: Help with INSERT into 2 tables
  In-Reply-To: <558f8e45.0111130542.1e617f99@posting.google.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