UPDATE using subquery with joined tables

From: "Sebastian P(dot) Luque" <spluque(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: UPDATE using subquery with joined tables
Date: 2012-12-04 19:52:39
Message-ID: 87txs161dk.fsf@kolob.subpolar.dyndns.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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.field1 LIKE '%mypattern%';

I am not sure how to translate this into an UPDATE statement for fiel1
in table1 efficiently. Any tips welcome.

Cheers,

--
Seb

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Gavin Flower 2012-12-04 20:00:36 Re: Which is faster: char(14) or varchar(14)
Previous Message icholy 2012-12-04 19:45:00 Re: libpq error message deallocation