Re: [GENERAL] INSERT... WHERE

2013-01-16 Thread David Johnston
Robert James wrote > On 1/13/13, Chris Angelico < > rosuav@ > > wrote: >> On Mon, Jan 14, 2013 at 3:37 PM, Robert James < > srobertjames@ > > >> wrote: >>> Thanks. But how do I do that where I have many literals? Something >>> like: >>> >>> INSERT INTO seltest (id, a, b) SELECT (1,2,3),(4,5,6)

Re: [GENERAL] INSERT... WHERE

2013-01-15 Thread Serge Fonville
Hmm, nvm :-( PostgreSQL does not yet support MERGE... Kind regards/met vriendelijke groet, Serge Fonville http://www.sergefonville.nl Convince Microsoft! They need to add TRUNCATE PARTITION in SQL Server https://connect.microsoft.com/SQLServer/feedback/details/417926/truncate-partition-of-part

Re: [GENERAL] INSERT... WHERE

2013-01-15 Thread Serge Fonville
Hi, Based on my understanding of the problem, would this be possible to solve with a MERGE statement? HTH Kind regards/met vriendelijke groet, Serge Fonville http://www.sergefonville.nl Convince Microsoft! They need to add TRUNCATE PARTITION in SQL Server https://connect.microsoft.com/SQLServ

Re: [GENERAL] INSERT... WHERE

2013-01-14 Thread Darren Duncan
On 2013.01.13 6:00 PM, Robert James wrote: I have a lot of VALUES I want to INSERT. But only a subset of them - only those that meet a JOIN criteria involving another table. I could INSERT them into a temp table, and then do a SELECT INTO. But do I need to do that? Is there any way to do a IN

Re: [GENERAL] INSERT... WHERE

2013-01-14 Thread Abel Abraham Camarillo Ojeda
On Sun, Jan 13, 2013 at 10:37 PM, Robert James wrote: > On 1/13/13, Ian Lawrence Barwick wrote: > > 2013/1/14 Robert James : > >> I have a lot of VALUES I want to INSERT. But only a subset of them - > >> only those that meet a JOIN criteria involving another table. > >> > >> I could INSERT them

Re: [GENERAL] INSERT... WHERE

2013-01-14 Thread Gavin Flower
On 15/01/13 09:43, Chris Angelico wrote: On Tue, Jan 15, 2013 at 5:26 AM, Robert James wrote: On 1/13/13, Chris Angelico wrote: On Mon, Jan 14, 2013 at 3:37 PM, Robert James wrote: Thanks. But how do I do that where I have many literals? Something like: INSERT INTO seltest (id, a, b) SELE

Re: [GENERAL] INSERT... WHERE

2013-01-14 Thread Chris Angelico
On Tue, Jan 15, 2013 at 5:26 AM, Robert James wrote: > On 1/13/13, Chris Angelico wrote: >> On Mon, Jan 14, 2013 at 3:37 PM, Robert James >> wrote: >>> Thanks. But how do I do that where I have many literals? Something like: >>> >>> INSERT INTO seltest (id, a, b) SELECT (1,2,3),(4,5,6),(7,8,9)

Re: [GENERAL] INSERT... WHERE

2013-01-14 Thread Robert James
On 1/13/13, Chris Angelico wrote: > On Mon, Jan 14, 2013 at 3:37 PM, Robert James > wrote: >> Thanks. But how do I do that where I have many literals? Something like: >> >> INSERT INTO seltest (id, a, b) SELECT (1,2,3),(4,5,6),(7,8,9) WHERE b >> IN (SELECT ...) > > You can use WITH clauses in cr

Re: [GENERAL] INSERT... WHERE

2013-01-13 Thread Chris Angelico
On Mon, Jan 14, 2013 at 3:37 PM, Robert James wrote: > Thanks. But how do I do that where I have many literals? Something like: > > INSERT INTO seltest (id, a, b) SELECT (1,2,3),(4,5,6),(7,8,9) WHERE b > IN (SELECT ...) You can use WITH clauses in crazy ways with PostgreSQL. I haven't actually t

Re: [GENERAL] INSERT... WHERE

2013-01-13 Thread Robert James
On 1/13/13, Ian Lawrence Barwick wrote: > 2013/1/14 Robert James : >> I have a lot of VALUES I want to INSERT. But only a subset of them - >> only those that meet a JOIN criteria involving another table. >> >> I could INSERT them into a temp table, and then do a SELECT INTO. But >> do I need to

Re: [GENERAL] INSERT... WHERE

2013-01-13 Thread Ian Lawrence Barwick
2013/1/14 Robert James : > I have a lot of VALUES I want to INSERT. But only a subset of them - > only those that meet a JOIN criteria involving another table. > > I could INSERT them into a temp table, and then do a SELECT INTO. But > do I need to do that? Is there any way to do a INSERT... VAL

Re: [GENERAL] INSERT... WHERE

2013-01-13 Thread Scott Marlowe
On Sun, Jan 13, 2013 at 7:00 PM, Robert James wrote: > I have a lot of VALUES I want to INSERT. But only a subset of them - > only those that meet a JOIN criteria involving another table. > > I could INSERT them into a temp table, and then do a SELECT INTO. But > do I need to do that? Is there

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

[GENERAL] Insert where not duplicate

2000-12-19 Thread Bryan White
I need to insert a bunch of records in a transaction. The transaction must not abort if the a duplicate is found. I know I have seen the syntax for the before. Can someone jog my memory? Bryan White, ArcaMax.com, VP of Technology The avalanche has already begun. It is too late for the pebbles