Re: UPDATE FROM syntax

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Paul Makepeace <postgresql(dot)org(at)paulm(dot)com>
Cc: PostgreSQL Novice <pgsql-novice(at)postgresql(dot)org>
Subject: Re: UPDATE FROM syntax
Date: 2004-03-03 14:15:17
Message-ID: 200403031415.i23EFHv21979@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Paul Makepeace wrote:
> [this didn't apparently make it thru' to pgsql-docs]
>
> Hi, is there any documentation for Pg's UPDATE FROM (apparently
> non-standard) syntax? It is mentioned briefly in \h update and not at
> all in http://www.postgresql.org/docs/7.3/static/dml-update.html
> or http://www.postgresql.org/docs/7.3/static/queries-table-expressions.html
> (directly).
>
> I solved my own problem but was still curious since it's non-standard if
> there's a "more standard" way of updating a table from another query.
>
> ALTER TABLE components ADD COLUMN default_body TEXT;
>
> UPDATE components SET default_body = bb.body
> FROM (SELECT b.body, cpb.component_id
> FROM componentspagesbodies cpb NATURAL JOIN bodies b
> WHERE cpb.page_id IS NULL) AS bb
> WHERE bb.component_id = components.component_id;
>
> (Incidently, I tried UPDATE components c SET ... c.component_id but the
> parser wasn't happy with it.)
>
> Paul
>
> (PS and now at least one working UPDATE FROM example is online ;-)

Try the UPDATE reference page in the docs.

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message M. Bastin 2004-03-03 17:32:34 system tables
Previous Message Joe 2004-03-03 05:35:38 Re: Initializing tables from flat files