Re: [GENERAL] INSERT WHERE NOT EXISTS

2003-06-26 Thread Tom Lane
Lincoln Yeoh <[EMAIL PROTECTED]> writes: > (Related: I also suggested arbitrary user locks years back, but I wasn't > able to implement them.) Don't we have 'em already? See contrib/userlock/. regards, tom lane ---(end of broadcast)--

Re: [GENERAL] INSERT WHERE NOT EXISTS

2003-06-26 Thread Lincoln Yeoh
That's why I resorted to "lock table", select, then insert/update. You have to block all the reads of other processes that are considering an insert. This is not great for performance, but I was certain it will work, unlike the race-vulnerable suggestions (are people here actually using those?

FW: [GENERAL] INSERT WHERE NOT EXISTS

2003-06-26 Thread Benjamin Jury
> // check if entry already exists > SELECT COUNT(*) FROM tablename WHERE [cond] > .. > if($count >0) > UPDATE > else > INSERT > > but this will double the hit to the database server, because > for every > operation I need to do SELECT COUNT(*) first. The data itself > is not a lot, > and

Re: [GENERAL] INSERT WHERE NOT EXISTS

2003-06-25 Thread Ian Barwick
On Wednesday 25 June 2003 21:37, Mike Mascari wrote: > Ian Barwick wrote: > > On Wednesday 25 June 2003 20:06, Reuben D. Budiardja wrote: (...) > > This kind of query should work; just leave out the "FROM dummy_table" > > bit. (in Oracle it would be "FROM dual"). > > I proposed that same solution

Re: [GENERAL] INSERT WHERE NOT EXISTS

2003-06-25 Thread Reuben D. Budiardja
On Wednesday 25 June 2003 03:26 pm, Ian Barwick wrote: > > I vaguely remember in Oracle, there is something like this: > > > > INSERT INTO mytable > > SELECT 'value1', 'value2' > > FROM dummy_table > > WHERE NOT EXISTS > > (SELECT NULL FROM mytable > > WHERE mycon

Re: [GENERAL] INSERT WHERE NOT EXISTS

2003-06-25 Thread Mike Mascari
Ian Barwick wrote: > On Wednesday 25 June 2003 20:06, Reuben D. Budiardja wrote: > >>Hi, >>I am developing application with PHP as the front end, PGSQL as the >>backend. I am trying to figure out what's the best way to do this. >>I want to check if an entry already exists in the table. If it does

Re: [GENERAL] INSERT WHERE NOT EXISTS

2003-06-25 Thread Reuben D. Budiardja
On Wednesday 25 June 2003 03:04 pm, scott.marlowe wrote: > Just wrap it in a transaction: > > begin; > select * from table where somefield='somevalue'; > (in php code) > if pg_num_rows>1... > update table set field=value where somefield=somevalue; > else > insert into table (field) values (value);

Re: [GENERAL] INSERT WHERE NOT EXISTS

2003-06-25 Thread Ian Barwick
On Wednesday 25 June 2003 20:06, Reuben D. Budiardja wrote: > Hi, > I am developing application with PHP as the front end, PGSQL as the > backend. I am trying to figure out what's the best way to do this. > I want to check if an entry already exists in the table. If it does, then I > will do > UPDA

Re: [GENERAL] INSERT WHERE NOT EXISTS

2003-06-25 Thread scott.marlowe
Just wrap it in a transaction: begin; select * from table where somefield='somevalue'; (in php code) if pg_num_rows>1... update table set field=value where somefield=somevalue; else insert into table (field) values (value); commit; On Wed, 25 Jun 2003, Reuben D. Budiardja wrote: > > Hi, > I am

[GENERAL] INSERT WHERE NOT EXISTS

2003-06-25 Thread Reuben D. Budiardja
Hi, I am developing application with PHP as the front end, PGSQL as the backend. I am trying to figure out what's the best way to do this. I want to check if an entry already exists in the table. If it does, then I will do UPDATE tablename otherwise, I will do INSER INTO tablename... W