From: | Rainer Pruy <Rainer(dot)Pruy(at)Acrys(dot)COM> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Create loop in postgresql |
Date: | 2012-09-03 16:12:25 |
Message-ID: | 5044D6E9.2000105@acrys.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Try it with parentheses around the (SELECT....).
On 03.09.2012 18:06, Robert Buckley wrote:
> this give an error.
>
> select name,ges_kw_zgb, SELECT round(100 * (ges_kw_zgb / (select
> sum(ges_kw_zgb) From energie.tennet_auswertung_2010)),2);
>
> ERROR: syntax error at or near "SELECT"
> LINE 2: select name,ges_kw_zgb, SELECT round(100 * (ges_kw_zgb / (se...
>
> ------------------------------------------------------------------------
> *Von:* salah jubeh <s_jubeh(at)yahoo(dot)com>
> *An:* Robert Buckley <robertdbuckley(at)yahoo(dot)com>;
> "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
> *Gesendet:* 17:45 Montag, 3.September 2012
> *Betreff:* Re: [GENERAL] Create loop in postgresql
>
> I am wondering why do not you write it like this
>
> select name,ges_kw_zgb, select round(100 * (ges_kw_zgb / (select
> sum(ges_kw_zgb) From energie.tennet_auswertung_2010)),2) ......
>
> Regards
>
>
> ------------------------------------------------------------------------
> *From:* Robert Buckley <robertdbuckley(at)yahoo(dot)com>
> *To:* "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
> *Sent:* Monday, September 3, 2012 5:30 PM
> *Subject:* [GENERAL] Create loop in postgresql
>
> Hi,
>
> I am trying to loop through the records in a table and update a
> column. I can do this with a case statement but I would like to
> simplify this to a simple loop statement. I can´t seem to work out how
> to do it though.
>
> Here is the case statement.
>
> select name,ges_kw_zgb,
> case
> When name='Bad Harzburg' then (select round(100 * (ges_kw_zgb /
> (select sum(ges_kw_zgb) From energie.tennet_auswertung_2010)),2))
> When name='Braunlage' then (select round(100 * (ges_kw_zgb / (select
> sum(ges_kw_zgb) From energie.tennet_auswertung_2010)),2))
> When name='Braunschweig' then (select round(100 * (ges_kw_zgb /
> (select sum(ges_kw_zgb) From energie.tennet_auswertung_2010)),2))
> When name='Büddenstedt' then (select round(100 * (ges_kw_zgb / (select
> sum(ges_kw_zgb) From energie.tennet_auswertung_2010)),2))
>
> End as z
>
> from energie.tennet_auswertung_2010
> ;
>
>
> Instead of having to write the name variable in the function, I would
> just like to iterate through each record and execute the select
> round(100 * (ges_kw_zgb / (select sum(ges_kw_zgb) From
> energie.tennet_auswertung_2010)),2) command.
>
> If anyone can help I´d me grateful,
>
> cheers,
>
> Rob
>
>
>
>
From | Date | Subject | |
---|---|---|---|
Next Message | Raymond O'Donnell | 2012-09-03 16:16:42 | Re: Create loop in postgresql |
Previous Message | Robert Buckley | 2012-09-03 16:06:58 | Re: Create loop in postgresql |