dbTalk Databases Forums  

Design question regarding arrays

comp.databases.postgresql.novice comp.databases.postgresql.novice


Discuss Design question regarding arrays in the comp.databases.postgresql.novice forum.



Reply
 
Thread Tools Display Modes
  #11  
Old   
Michael Glaesemann
 
Posts: n/a

Default Re: Design question regarding arrays - 08-09-2004 , 05:26 AM







On Aug 9, 2004, at 7:14 PM, Sean Davis wrote:

Quote:
I'm a novice, too, but why not look up the value in the sequence and
increment it before doing any inserting? If you are doing all the
inserts
at the same time (more or less), then you can just use this value in
the
insert into both tables. Put all of this inside one transaction.
Actually, I don't even think it has to be inside a transaction. Beyond
being transaction safe, currval is session safe (correcting something I
said in an earlier post). As long as you don't put another insert or
otherwise manipulate the sequence in the same session, you can trust
currval

Michael Glaesemann
grzm myrealbox com


---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo (AT) postgresql (DOT) org



Reply With Quote
  #12  
Old   
Oliver Fromme
 
Posts: n/a

Default Re: Design question regarding arrays - 08-09-2004 , 05:29 AM







Sean Davis wrote:
Quote:
I'm a novice, too, but why not look up the value in the sequence and
increment it before doing any inserting? If you are doing all the inserts
at the same time (more or less), then you can just use this value in the
insert into both tables. Put all of this inside one transaction.
That won't work if another process is trying to do the same
thing at the same time. They both get the same value when
they look it up, so there will be an ID collision.

Best regards
Oliver

--
Oliver Fromme, secnetix GmbH & Co KG, Oettingenstr. 2, 80538 München
Any opinions expressed in this message may be personal to the author
and may not necessarily reflect the opinions of secnetix in any way.

"Being really good at C++ is like being really good
at using rocks to sharpen sticks."
-- Thant Tessman

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings



Reply With Quote
  #13  
Old   
Stephan Szabo
 
Posts: n/a

Default Re: Design question regarding arrays - 08-09-2004 , 09:22 AM



On Mon, 9 Aug 2004, Oliver Fromme wrote:

Quote:
Sean Davis wrote:
I'm a novice, too, but why not look up the value in the sequence and
increment it before doing any inserting? If you are doing all the inserts
at the same time (more or less), then you can just use this value in the
insert into both tables. Put all of this inside one transaction.

That won't work if another process is trying to do the same
thing at the same time. They both get the same value when
they look it up, so there will be an ID collision.
It should be safe if you're using a sequence and using nextval() to get
the value that you are using in both insert statements. A second session
will not get the same value you just got from nextval barring a cycling
sequence generator that wraps back to the same number between the nextval
and insert.

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo (AT) postgresql (DOT) org



Reply With Quote
  #14  
Old   
Sean Davis
 
Posts: n/a

Default Re: Design question regarding arrays - 08-09-2004 , 09:34 AM



That is exactly what I had in mind but wasn't clear on.

Sean
----- Original Message -----
From: "Stephan Szabo" <sszabo (AT) megazone (DOT) bigpanda.com>
To: "Oliver Fromme" <olli (AT) lurza (DOT) secnetix.de>
Cc: "Sean Davis" <sdavis2 (AT) mail (DOT) nih.gov>; "Michael Glaesemann"
<grzm (AT) myrealbox (DOT) com>; <pgsql-novice (AT) postgresql (DOT) org>; "A Gilmore"
<agilmore (AT) shaw (DOT) ca>
Sent: Monday, August 09, 2004 10:22 AM
Subject: Re: [NOVICE] Design question regarding arrays


Quote:
On Mon, 9 Aug 2004, Oliver Fromme wrote:

Sean Davis wrote:
I'm a novice, too, but why not look up the value in the sequence and
increment it before doing any inserting? If you are doing all the
inserts
at the same time (more or less), then you can just use this value in
the
insert into both tables. Put all of this inside one transaction.

That won't work if another process is trying to do the same
thing at the same time. They both get the same value when
they look it up, so there will be an ID collision.

It should be safe if you're using a sequence and using nextval() to get
the value that you are using in both insert statements. A second session
will not get the same value you just got from nextval barring a cycling
sequence generator that wraps back to the same number between the nextval
and insert.



---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo (AT) postgresql (DOT) org)



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.