From: | Dave Cramer <pg(at)fastcrypt(dot)com> |
---|---|
To: | Roland Walter <rwa(at)mosaic-ag(dot)com> |
Cc: | Nico <nicohmail-postgresql(at)yahoo(dot)com>, pgsql-jdbc(at)postgresql(dot)org |
Subject: | Re: getting a sequence value |
Date: | 2005-03-21 12:53:47 |
Message-ID: | 423EC3DB.1070301@fastcrypt.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-jdbc |
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
From | Date | Subject | |
---|---|---|---|
Next Message | Dave Cramer | 2005-03-21 12:55:22 | Re: getting a sequence value |
Previous Message | Guillaume Cottenceau | 2005-03-21 12:52:46 | Re: getting a sequence value |