Re: Simple SQL-syntax - Mailing list pgsql-sql

From Josh Berkus
Subject Re: Simple SQL-syntax
Date
Msg-id web-105447@davinci.ethosmedia.com
Whole thread Raw
In response to Simple SQL-syntax  ("Fredrik Thunberg" <fredrik@datessa.se>)
Responses Re: Simple SQL-syntax  ("Josh Berkus" <josh@agliodbs.com>)
List pgsql-sql
Robby,

> Do you know if, internally there's any difference between
> 
> UPDATE A,B SET a.f1 = b.f1 WHERE a.i = b.i;
> 
>   -and-
> 
> UPDATE A SET a.f1 = b.f2 FROM B WHERE a.i = b.i;
> 
> Just wondering why the SQL standard would be broken in this
> case---and if there's any reason to learn this particular
> aspect of Postgres functionality....

Only if you want to use JOINS, sub-selects, and/or aliasing in your
UPDATE statement.  For example, I have a table that caches subtotals of
its detail-level subtable:

UPDATE invoice SET invoice_total = total_of_items
FROM (SELECT invoice_id, sum(item_amount) FROM invoice_items) iit
WHERE iit.invoice_id = invoices.id;

-Josh Berkus


______AGLIO DATABASE SOLUTIONS___________________________                                      Josh Berkus Complete
informationtechnology      josh@agliodbs.com  and data management solutions       (415) 565-7293 for law firms, small
businesses       fax 621-2533   and non-profit organizations.      San Francisco
 


pgsql-sql by date:

Previous
From: "omid omoomi"
Date:
Subject: split/explode functions
Next
From: Laurette Cisneros
Date:
Subject: quick server c question