Re: [GENERAL] UPDATE using subquery with joined tables

2012-12-04 Thread Paul Jungwirth
Seems like this should work (untested though): UPDATE table1 a SET field1 = a.field1 || (SELECT regexp_replace(b.field1, '', '...') FROM table2 b WHERE a.id = b.id AND b.field1 LIKE '') WHERE a.field1 NOT LIKE '' Paul On Tue, Dec 4, 2012 at 11:52 AM, Sebastian P. Luque wrote: > Hi

Re: [GENERAL] UPDATE using subquery with joined tables

2012-12-04 Thread David Johnston
> -Original Message- > From: pgsql-general-ow...@postgresql.org [mailto:pgsql-general- > ow...@postgresql.org] On Behalf Of Sebastian P. Luque > Sent: Tuesday, December 04, 2012 2:53 PM > To: pgsql-general@postgresql.org > Subject: [GENERAL] UPDATE using subquery

[GENERAL] UPDATE using subquery with joined tables

2012-12-04 Thread Sebastian P. Luque
Hi, I need to update field1 in table1, gathering data from field1 in table2. The following SELECT shows the data as it needs to be updated: SELECT a.field1 || regexp_replace(b.field1, '.*(mypattern)', e'. \\1') FROM table1 a JOIN table2 b USING (id) WHERE a.field1 NOT LIKE '%mypattern%' AND b.fie