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 8C7E8563EF for ; Mon, 21 Mar 2005 12:53:51 +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 77248-02 for ; Mon, 21 Mar 2005 12:53:50 +0000 (GMT) Received: from net2.micro-automation.com (net2.micro-automation.com [64.7.141.29]) by svr1.postgresql.org (Postfix) with SMTP id 2BAB1563EE for ; Mon, 21 Mar 2005 12:53:49 +0000 (GMT) Received: (qmail 24285 invoked from network); 21 Mar 2005 12:52:47 -0000 Received: from dcdsl.ebox.com (HELO ?192.168.1.36?) (davec@64.7.143.116) by net2.micro-automation.com with SMTP; 21 Mar 2005 12:52:47 -0000 Message-ID: <423EC3DB.1070301@fastcrypt.com> Date: Mon, 21 Mar 2005 07:53:47 -0500 From: Dave Cramer Reply-To: pg@fastcrypt.com Organization: Postgres International User-Agent: Mozilla Thunderbird 1.0 (X11/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Roland Walter Cc: Nico , pgsql-jdbc@postgresql.org Subject: Re: getting a sequence value References: <423EC07B.6080406@mosaic-ag.com> In-Reply-To: <423EC07B.6080406@mosaic-ag.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.035 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200503/175 X-Sequence-Number: 12567 Roland, That works too! Great idea. I'm so used to doing it the other way as most times I need the primary key too in my java class for identity purposes. Dave Roland Walter wrote: > Nico schrieb: > >> 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(???, ...); >> >> >> > How about INSERT INTO "tblTable2 ("Field2", ...) VALUES > (currval('public."TbleTable1_FieldID_seq"'), ...); > > But you have to do this in the same connection to the database, that > did insert into table 1. > -- Dave Cramer http://www.postgresintl.com 519 939 0336 ICQ#14675561