FAQ

On Mon, Jul 12, 2010 at 4:31 AM, Matthew Sleight wrote:

I can write it in normal SQL, but postgre comes up with an error on the
first ‘inner join’.
Correct, inner joins in an update statement are violations of the SQL
standard and are not supported by PostgreSQL. The following link
explains correct syntax that can be used with an update statement:

http://www.postgresql.org/docs/9.0/static/sql-update.html
The online help (that is not very good)
If it isn't very good, do you have any suggestions on how it can be improved?


--SQL compliant syntax
UPDATE public_consumption_hanson_uk_el_clear AS A
SET acutal_estimate
= ( SELECT MIN( C.actual_estimate ) AS minimum_actual_estimate
FROM public_consumption_hanson2 AS C
WHERE C.supply_day = A.supply_day
AND C.supply_brand_name = A.supply_brand_name
AND C.meter_no = A.meterreference
AND C.mpan = A.meterpiontreference ) AS B(
minimum_actual_estimate );

--Postgresql extension syntax
UPDATE public_consumption_hanson_uk_el_clear AS A
SET acutal_estimate = B.minimum_actual_estimate
FROM ( SELECT supply_day, supply_brand_name, meter_no, mpan,
MIN( C.actual_estimate ) AS minimum_actual_estimate
FROM public_consumption_hanson2 AS C
GROUP BY supply_day, supply_brand_name, meter_no ) AS B
WHERE B.supply_day = A.supply_day
AND B.supply_brand_name = A.supply_brand_name
AND B.meter_no = A.meterreference
AND B.mpan = A.meterpiontreference ;


--
Regards,
Richard Broersma Jr.

Visit the Los Angeles PostgreSQL Users Group (LAPUG)
http://pugs.postgresql.org/lapug

Search Discussions

Discussion Posts

Previous

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 2 of 2 | next ›
Discussion Overview
grouppgsql-novice @
categoriespostgresql
postedJul 12, '10 at 11:38a
activeJul 12, '10 at 4:25p
posts2
users2
websitepostgresql.org
irc#postgresql

People

Translate

site design / logo © 2022 Grokbase