Re: [SQL] Passing function parameters to regexp_replace

2011-09-17 Thread Tim Landscheidt
Leif Biberg Kristensen wrote: > On Saturday 17. September 2011 19.07.03 Tim Landscheidt wrote: >> Leif Biberg Kristensen wrote: >> > UPDATE sources SET source_text = regexp_replace(source_text, >> > E'n="(.*?)$1(.*?)"', E'n="\\1$2\\2"', 'g') where source_text like >> > '%n="%$1%">%' >> Try: >>

Re: [SQL] Passing function parameters to regexp_replace

2011-09-17 Thread Leif Biberg Kristensen
On Saturday 17. September 2011 19.07.03 Tim Landscheidt wrote: > Leif Biberg Kristensen wrote: > > > UPDATE sources SET source_text = regexp_replace(source_text, > > E'n="(.*?)$1(.*?)"', E'n="\\1$2\\2"', 'g') where source_text like > > '%n="%$1%">%' > > Try: > > UPDATE sources SET source_text =

Re: [SQL] Passing function parameters to regexp_replace

2011-09-17 Thread Tim Landscheidt
Leif Biberg Kristensen wrote: >> UPDATE sources SET source_text = regexp_replace(source_text, >> E'n="(.*?)$1(.*?)"', E'n="\\1$2\\2"', 'g') where source_text like >> '%n="%$2%">%'; > Sorry, I pasted a literal replacement, and substituted the parameters by hand. > The expression should of course

Re: [SQL] Use select and update together

2011-09-17 Thread Tom Lane
Guillaume Lelarge writes: > On Sat, 2011-09-17 at 16:56 +0200, Andreas wrote: >> select * from ( >> update tbl set val = 1 where key in ( 1, 2, 3, 4, 5 ) returning * >> ) as x >> >> wouldn't work even in PG 9.1. >> So what data structure is coming out of an "update ... returning *" >> statement?

Re: [SQL] Use select and update together

2011-09-17 Thread Guillaume Lelarge
On Sat, 2011-09-17 at 16:56 +0200, Andreas wrote: > Am 13.09.2011 07:50, schrieb pasman pasmański: > > In 8.4 this syntax is not implemented. > > select * from ( > update tbl set val = 1 where key in ( 1, 2, 3, 4, 5 ) returning * > ) as x > > wouldn't work even in PG 9.1. > So what data structure

Re: [SQL] insert or update within transaction

2011-09-17 Thread Josh Kupershmidt
On Sat, Sep 17, 2011 at 10:52 AM, Andreas wrote: > Instead of the update the query fails with an double key value error for the > primary key. > Shouldn't the insert fail, get rolled back and then exercute an update > instead successfully? Yes, and that is indeed what I see when I run your exampl

Re: [SQL] Use select and update together

2011-09-17 Thread Andreas
Am 13.09.2011 07:50, schrieb pasman pasmański: In 8.4 this syntax is not implemented. select * from ( update tbl set val = 1 where key in ( 1, 2, 3, 4, 5 ) returning * ) as x wouldn't work even in PG 9.1. So what data structure is coming out of an "update ... returning *" statement? It obvio

[SQL] insert or update within transaction

2011-09-17 Thread Andreas
Hi, http://www.postgresql.org/docs/current/static/sql-update.html has an example where an either an insert or update is done according if a key already exists. The example is about wines. I did it with numbers. drop table if exists tbl; create table tbl ( key int primary key, val int ); insert

Re: [SQL] Sorting of data from two tables

2011-09-17 Thread David Johnston
On Sep 17, 2011, at 9:32, "R. Smith" wrote: > > What I want to do is do a query joining table A with B and sorting > firstly on a field in Table A then on several fields in Table B. > > > SELECT a.gdn_gdn, a.gdn_custref, a.gdn_date, a.gdn_address_name, > a.gdn_method, b.gdn_stockref, b.gdn_row

[SQL] Sorting of data from two tables

2011-09-17 Thread R. Smith
Greetings folks, This is a follow up to my initial message some time ago. Now I have got all the details together. I have two tables. Table A - Which contains one row per entry Table B - Which contains multiple rows per entry Table B relates to Table A by a field say called ID. Table A in this

Re: [SQL] Passing function parameters to regexp_replace

2011-09-17 Thread Leif Biberg Kristensen
On Saturday 17. September 2011 13.21.43 Leif Biberg Kristensen wrote: > UPDATE sources SET source_text = regexp_replace(source_text, > E'n="(.*?)$1(.*?)"', E'n="\\1$2\\2"', 'g') where source_text like > '%n="%$2%">%'; Sorry, I pasted a literal replacement, and substituted the parameters by hand.

[SQL] Passing function parameters to regexp_replace

2011-09-17 Thread Leif Biberg Kristensen
I'm trying to write a sql or plpgsql function update_nametags(TEXT, TEXT) which does a replace on this form: UPDATE sources SET source_text = regexp_replace(source_text, E'n="(.*?)$1(.*?)"', E'n="\\1$2\\2"', 'g') where source_text like '%n="%$2%">%'; But I can't find out how to escape the para