dbTalk Databases Forums  

UPDATE FROM syntax

comp.databases.postgresql.novice comp.databases.postgresql.novice


Discuss UPDATE FROM syntax in the comp.databases.postgresql.novice forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Paul Makepeace
 
Posts: n/a

Default UPDATE FROM syntax - 02-27-2004 , 07:17 AM






[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/s...ml-update.html
or http://www.postgresql.org/docs/7.3/s...pressions.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 ;-)

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

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

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html


Reply With Quote
  #2  
Old   
Bruce Momjian
 
Posts: n/a

Default Re: UPDATE FROM syntax - 03-03-2004 , 08:15 AM






Paul Makepeace wrote:
Quote:
[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/s...ml-update.html
or http://www.postgresql.org/docs/7.3/s...pressions.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.pa.us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.