UPDATE FROM syntax

From: Paul Makepeace <postgresql(dot)org(at)paulm(dot)com>
To: PostgreSQL Docs <pgsql-docs(at)postgresql(dot)org>
Subject: UPDATE FROM syntax
Date: 2004-02-23 12:11:05
Message-ID: 20040223121105.GO8784@mythix.realprogrammers.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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).

[moving a bit OT for docs?]

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 ;-)

--
Paul Makepeace ................................ http://paulm.com/ecademy

"What is it i am yapping about? Three things: location, location,
location."
-- http://paulm.com/toys/surrealism/

Responses

Browse pgsql-docs by date

  From Date Subject
Next Message Halley Pacheco de Oliveira 2004-02-23 18:46:12 PostgreSQL 7.4 Documentation - perform.sgml
Previous Message Henry B. Hotz 2004-02-21 23:01:04 Re: Request temporary freeze of libpgtcl chapter in manual