Re:

From: Richard Broersma <richard(dot)broersma(at)gmail(dot)com>
To: Matthew Sleight <matthewsleight(at)encore-international(dot)net>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re:
Date: 2010-07-12 16:25:50
Message-ID: AANLkTinP_wjv47VVWK-4i6ECdpceoXbwjDhZtYBuNgsc@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Mon, Jul 12, 2010 at 4:31 AM, Matthew Sleight
<matthewsleight(at)encore-international(dot)net> 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

In response to

  • at 2010-07-12 11:31:21 from Matthew Sleight

Browse pgsql-novice by date

  From Date Subject
Next Message Michael Swierczek 2010-07-12 18:22:07 Re: Triggers, Stored Procedures to Aggregate table ?
Previous Message Alan Hodgson 2010-07-12 15:57:59 Re: SQL from Linux command line