Re: [HACKERS] Agregates in update? - Mailing list pgsql-hackers

From Bruce Momjian
Subject Re: [HACKERS] Agregates in update?
Date
Msg-id 199804270321.XAA19856@candle.pha.pa.us
Whole thread Raw
In response to Agregates in update?  (Aleksey Dashevsky <postgres@luckynet.co.il>)
List pgsql-hackers
Added to TODO list.
>
> hi, All!
> Just installed PG 6.3.1 -- really great job, thank you guys!
>
> But this morning I decided to play a bit with aggregate functions on
> update and got a bit strange(for me, at least :-) result.
> Here is an exmaple of what I did:
> ========================================
> Let's create two simple tables
>   create table a (name text sum float);
>   create table b (name text ,val float);
>
> --and then populate them with rows
>
>   insert into a values ('bob', 0.0);
>   insert into a values ('john', 0.0 );
>   insert into a values ('mike', 0.0);
>
>   insert into b values ('bob', 1.0);
>   insert into b values ('bob', 2.0);
>   insert into b values ('bob', 3.0);
>   insert into b values ('john', 4.0);
>   insert into b values ('john', 5.0);
>   insert into b values ('john', 6.0);
>   insert into b values ('mike', 670);
>   insert into b values ('mike', 8.0);
>   insert into b values ('mike', 9.0);
>
> --now I want to update "sum" fields of table a in a way they will conatain
> --sums of field "val" from table b groupped by name
> --and use for this following query:
> update a set sum=sum(b.val) where name=b.name ;
> --Now
>   select * from a;
> -- gives me:
> name|sum
> ----+---
> john|  0
> mike|  0
> bob |708
> (3 rows)
>
> ===================
> Now I'm wondering if there is reall problem in PostgreSQL or my
> misundersanding of something important in SQL.
>
> I'm running Linux-2.0.30(Slackware) and gcc-2.7.2.3
>
> Thank you,
> Aleksey.
>
>
>


--
Bruce Momjian                          |  830 Blythe Avenue
maillist@candle.pha.pa.us              |  Drexel Hill, Pennsylvania 19026
  +  If your life is a hard drive,     |  (610) 353-9879(w)
  +  Christ can be your backup.        |  (610) 853-3000(h)

pgsql-hackers by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: [HACKERS] pg_type populated incorrectly in some cases?
Next
From: Bruce Momjian
Date:
Subject: Re: [HACKERS] escape character \