pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Dave Cramer <pg@fastcrypt.com>
To: Roland Walter <rwa@mosaic-ag.com>
Cc: Nico <nicohmail-postgresql@yahoo.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: getting a sequence value
Date: Mon, 21 Mar 2005 07:53:47 -0500
Message-ID: <423EC3DB.1070301@fastcrypt.com> (raw)
In-Reply-To: <423EC07B.6080406@mosaic-ag.com>
References: <d1mb4u$1j89$1@news.hub.org>
	<423EC07B.6080406@mosaic-ag.com>

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




view thread (9+ messages)  latest in thread

Message-ID: <423EC3DB.1070301@fastcrypt.com>
Permalink:  ../423EC3DB.1070301@fastcrypt.com/
Also on:    postgresql.org/message-id/423EC3DB.1070301@fastcrypt.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 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: pg@fastcrypt.com, rwa@mosaic-ag.com, nicohmail-postgresql@yahoo.com
  Subject: Re: getting a sequence value
  In-Reply-To: <423EC3DB.1070301@fastcrypt.com>
  References: <d1mb4u$1j89$1@news.hub.org> <423EC07B.6080406@mosaic-ag.com> <423EC3DB.1070301@fastcrypt.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