X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 54EEA56469 for ; Mon, 21 Mar 2005 11:28:40 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 52268-02 for ; Mon, 21 Mar 2005 11:28:38 +0000 (GMT) Received: from floppy.pyrenet.fr (unknown [194.116.145.2]) by svr1.postgresql.org (Postfix) with ESMTP id F3DF05645A for ; Mon, 21 Mar 2005 11:28:37 +0000 (GMT) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id 9ACA730EA1; Mon, 21 Mar 2005 12:28:35 +0100 (MET) From: "Nico" X-Newsgroups: pgsql.interfaces.jdbc Subject: getting a sequence value Date: Mon, 21 Mar 2005 12:28:33 +0100 Organization: Hub.Org Networking Services Lines: 25 Message-ID: X-Complaints-To: usenet@news.hub.org X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-RFC2646: Format=Flowed; Original To: pgsql-jdbc@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=3.359 tagged_above=0 required=5 tests=FORGED_YAHOO_RCVD, PRIORITY_NO_NAME X-Spam-Level: *** X-Archive-Number: 200503/169 X-Sequence-Number: 12561 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.