Skip site navigation (1) Skip section navigation (2)

Re: [HACKERS] Agregates in update?

From: Bruce Momjian <maillist(at)candle(dot)pha(dot)pa(dot)us>
To: postgres(at)luckynet(dot)co(dot)il (Aleksey Dashevsky)
Cc: pgsql-hackers(at)postgreSQL(dot)org, pgsql-questions(at)postgreSQL(dot)org
Subject: Re: [HACKERS] Agregates in update?
Date: 1998-04-27 03:21:09
Message-ID: 199804270321.XAA19856@candle.pha.pa.us (view raw or flat)
Thread:
Lists: 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(at)candle(dot)pha(dot)pa(dot)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)

In response to

Responses

pgsql-hackers by date

Next:From: Bruce MomjianDate: 1998-04-27 03:34:25
Subject: Re: [HACKERS] escape character \
Previous:From: Bruce MomjianDate: 1998-04-27 03:17:24
Subject: Re: [HACKERS] pg_type populated incorrectly in some cases?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group