Re: [GENERAL] conditional insert

2011-09-08 Thread Lincoln Yeoh
At 03:51 AM 9/8/2011, Merlin Moncure wrote: yeah -- but you only need to block selects if you are selecting in the inserting transaction (this is not a full upsert). if both writers are doing: begin; lock table foo exclusive; insert into foo select ... where ...; commit; is good enough. btw

Re: [GENERAL] conditional insert

2011-09-08 Thread Lincoln Yeoh
At 03:51 AM 9/8/2011, Merlin Moncure wrote: Don't you have to block SELECTs so that the SELECTs get serialized? Otherwise concurrent SELECTs can occur at the same time, find no existing rows, then all the inserts proceed and you get errors (or dupes). That's how Postgresql still works

Re: [GENERAL] conditional insert

2011-09-08 Thread Merlin Moncure
On Thu, Sep 8, 2011 at 9:14 AM, Lincoln Yeoh ly...@pop.jaring.my wrote: At 03:51 AM 9/8/2011, Merlin Moncure wrote: Don't you have to block SELECTs so that the SELECTs get serialized? Otherwise concurrent SELECTs can occur at the same time, find no existing rows, then all the inserts

Re: [GENERAL] conditional insert

2011-09-08 Thread Lincoln Yeoh
At 04:04 AM 9/8/2011, Andrew Sullivan wrote: On Wed, Sep 07, 2011 at 02:51:32PM -0500, Merlin Moncure wrote: @andrew s: going SERIALIZABLE doesn't help if you trying to eliminate cases that would push you into retrying the transaction. Well, no, of course. But why not catch the failure and

Re: [GENERAL] conditional insert

2011-09-08 Thread Andrew Sullivan
On Thu, Sep 08, 2011 at 10:31:39PM +0800, Lincoln Yeoh wrote: Doesn't catching the failure and retrying mean writing more code? Well, yes. OTOH, if you want to use upsert and you have to use other database systems too, then you'll need that other code also, since it's not standard. There

Re: [GENERAL] conditional insert

2011-09-07 Thread Lincoln Yeoh
At 05:23 AM 9/7/2011, Merlin Moncure wrote: On Tue, Sep 6, 2011 at 3:45 PM, Merlin Moncure mmonc...@gmail.com wrote: b) doesn't block reads if you lock in EXCLUSIVE mode. a) is the best way to go if you prefer to handle errors on the client and/or concurrency is important...c) otherwise.

Re: [GENERAL] conditional insert

2011-09-07 Thread Andrew Sullivan
On Wed, Sep 07, 2011 at 11:45:11PM +0800, Lincoln Yeoh wrote: Don't you have to block SELECTs so that the SELECTs get serialized? If you want to do that, why wouldn't you just use serializable mode? A -- Andrew Sullivan a...@crankycanuck.ca -- Sent via pgsql-general mailing list

Re: [GENERAL] conditional insert

2011-09-07 Thread Merlin Moncure
On Wed, Sep 7, 2011 at 10:45 AM, Lincoln Yeoh ly...@pop.jaring.my wrote: At 05:23 AM 9/7/2011, Merlin Moncure wrote: On Tue, Sep 6, 2011 at 3:45 PM, Merlin Moncure mmonc...@gmail.com wrote: b) doesn't block reads if you lock in EXCLUSIVE mode.  a) is the best way to go if you prefer to

Re: [GENERAL] conditional insert

2011-09-07 Thread Andrew Sullivan
On Wed, Sep 07, 2011 at 02:51:32PM -0500, Merlin Moncure wrote: @andrew s: going SERIALIZABLE doesn't help if you trying to eliminate cases that would push you into retrying the transaction. Well, no, of course. But why not catch the failure and retry? I guess I just don't get the problem,

Re: [GENERAL] conditional insert

2011-09-07 Thread Merlin Moncure
On Wed, Sep 7, 2011 at 3:04 PM, Andrew Sullivan a...@crankycanuck.ca wrote: On Wed, Sep 07, 2011 at 02:51:32PM -0500, Merlin Moncure wrote: @andrew s: going SERIALIZABLE doesn't help if you trying to eliminate cases that would push you into retrying the transaction. Well, no, of course.  But

Re: [GENERAL] conditional insert

2011-09-06 Thread Lincoln Yeoh
At 07:02 PM 9/5/2011, J. Hondius wrote: I agree that there are better ways to do this. But for me this works. (legacy driven situation) INSERT INTO tbinitialisatie (col1, col2) SELECT 'x', 'y' FROM tbinitialisatie WHERE not exists (select * from tbinitialisatie where col1 = 'x' and col2 =

Re: [GENERAL] conditional insert

2011-09-06 Thread Merlin Moncure
On Tue, Sep 6, 2011 at 1:50 PM, Lincoln Yeoh ly...@pop.jaring.my wrote: At 07:02 PM 9/5/2011, J. Hondius wrote: I agree that there are better ways to do this. But for me this works. (legacy driven situation) INSERT INTO tbinitialisatie (col1, col2)  SELECT 'x', 'y'  FROM tbinitialisatie  

Re: [GENERAL] conditional insert

2011-09-06 Thread Merlin Moncure
On Tue, Sep 6, 2011 at 3:45 PM, Merlin Moncure mmonc...@gmail.com wrote: On Tue, Sep 6, 2011 at 1:50 PM, Lincoln Yeoh ly...@pop.jaring.my wrote: At 07:02 PM 9/5/2011, J. Hondius wrote: I agree that there are better ways to do this. But for me this works. (legacy driven situation) INSERT

[GENERAL] conditional insert

2011-09-05 Thread Pau Marc Muñoz Torres
Hi follk i trying to performe a conditional insert into a table, indeed, what i'm trying to do is not insert a record into the table if that record exist googleling i found something like insert into XX values (1,2,3) where not exist (select ); but i'm having and error near where...

Re: [GENERAL] conditional insert

2011-09-05 Thread Achilleas Mantzios
Στις Monday 05 September 2011 12:38:34 ο/η Pau Marc Muñoz Torres έγραψε: Hi follk i trying to performe a conditional insert into a table, indeed, what i'm trying to do is not insert a record into the table if that record exist thats why primary/unique keys are for. isolate the columns

Re: [GENERAL] conditional insert

2011-09-05 Thread Raymond O'Donnell
On 05/09/2011 10:38, Pau Marc Muñoz Torres wrote: Hi follk i trying to performe a conditional insert into a table, indeed, what i'm trying to do is not insert a record into the table if that record exist googleling i found something like insert into XX values (1,2,3) where not exist

Re: [GENERAL] conditional insert

2011-09-05 Thread Thomas Kellerer
Pau Marc Muñoz Torres, 05.09.2011 11:38: Hi follk i trying to performe a conditional insert into a table, indeed, what i'm trying to do is not insert a record into the table if that record exist googleling i found something like insert into XX values (1,2,3) where not exist (select

Re: [GENERAL] conditional insert

2011-09-05 Thread Sim Zacks
On 09/05/2011 12:38 PM, Pau Marc Muoz Torres wrote: Hi follk i trying to performe a conditional insert into a table, indeed, what i'm trying to do is not insert a record into the table if that record exist googleling i found something like

Re: [GENERAL] conditional insert

2011-09-05 Thread Pau Marc Muñoz Torres
i don't see it clear, let me put an example i got the following table molec varchar(30) seq varchar(100) where I insert my values lets image that i have a record introduced as ('ubq', 'aadgylpittrs') how i can prevent to insert another record where molec='ubq' ? thanks 2011/9/5 Thomas

Re: [GENERAL] conditional insert

2011-09-05 Thread Sim Zacks
On 09/05/2011 01:37 PM, Pau Marc Muoz Torres wrote: i don't see it clear, let me put an example i got the following table molec varchar(30) seq varchar(100) where I insert my values lets image that i have a record introduced

Re: [GENERAL] conditional insert

2011-09-05 Thread Pau Marc Muñoz Torres
Ok , thanks Sim, now i see it P 2011/9/5 Sim Zacks s...@compulab.co.il ** On 09/05/2011 01:37 PM, Pau Marc Muñoz Torres wrote: i don't see it clear, let me put an example i got the following table molec varchar(30) seq varchar(100) where I insert my values lets image that i have

Re: [GENERAL] conditional insert

2011-09-05 Thread J. Hondius
I agree that there are better ways to do this. But for me this works. (legacy driven situation) INSERT INTO tbinitialisatie (col1, col2) SELECT 'x', 'y' FROM tbinitialisatie WHERE not exists (select * from tbinitialisatie where col1 = 'x' and col2 = 'y') LIMIT 1 Pau Marc Muoz Torres