pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Nico <nicohmail-postgresql@yahoo.com>
To: pgsql-jdbc@postgresql.org
Subject: getting a sequence value
Date: Mon, 21 Mar 2005 12:28:33 +0100
Message-ID: <d1mb4u$1j89$1@news.hub.org> (raw)

Hi,
I have two tables where the second table has a foreign key to the first one.
When I insert a row in the first one, I need the value of the ID generated 
by a sequence in the first table to insert it in the foreign key column in 
the second table. Except I don't know how to do this in Java/PostgreSQL... 
Anyone knows how?
Table data:
Table 1:
Field1 (integer) default: nextval('public."tblTable1_FieldID_seq"'::text)
other field...
Table 2:
Field1 (integer) default: nextval('public."tblTable2_FieldID_seq"':text)
Field2 (integer) foreign key that references to Field1 in Table 1...

So when I do this:
INSERT INTO "tblTable1"(other fields...) VALUES(...);
how do I know what to put in here?
INSERT INTO "tblTable2"("Field2", other fields...) VALUES(???, ...);

I know in MS SQL server and Oracle one uses an old and new resultset to 
resolve this issue, but haven't a clue how to do this in Java/PostgreSQL...

Nico. 





view thread (9+ messages)  latest in thread

Message-ID: <d1mb4u$1j89$1@news.hub.org>
Permalink:  ../d1mb4u$1j89$1@news.hub.org/
Also on:    postgresql.org/message-id/d1mb4u$1j89$1@news.hub.org

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: nicohmail-postgresql@yahoo.com
  Subject: Re: getting a sequence value
  In-Reply-To: <d1mb4u$1j89$1@news.hub.org>
  References: <d1mb4u$1j89$1@news.hub.org>

* 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