Strange primary key constraint influence to grouping - Mailing list pgsql-hackers

From Gražvydas Valeika
Subject Strange primary key constraint influence to grouping
Date
Msg-id CAO6eJZo_D20Tmxa1e1DEbc49atkiiXT3oR-kDHjhui2YKecQrA@mail.gmail.com
Whole thread Raw
Responses Re: Strange primary key constraint influence to grouping  (Andreas Karlsson <andreas@proxel.se>)
List pgsql-hackers
Hi,

accidentally found a our sql typo, which runs without errors on pg 9.1, but raises error on 9.0. It seems to me, that 9.0 behaviour was correct.

Reproducing case:

create table aaa(id integer NOT NULL, something double precision, constraint pk_aaa primary key (id));
insert into aaa values (1, 1), (2, null);
select 
id,
case 
when something is not null then 'something'
else 'something is null'
end as status
from 
aaa
group by id;
drop table aaa cascade;


In PG 9.0 this script complains that: column "aaa.something" must appear in the GROUP BY clause or be used in an aggregate function. Sorry, don't have 9.0 at my hands, but error message is similar to quoted. 
Same error is raised in 9.1 when ', constraint pk_aaa primary key (id)' is commented out.

With PK constraint in place, this script runs happily, without complaints.

Version with observerd behaviour: "PostgreSQL 9.1.1, compiled by Visual C++ build 1500, 32-bit"


Best regards,

Grazvydas

pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: how to create a non-inherited CHECK constraint in CREATE TABLE
Next
From: Andreas Karlsson
Date:
Subject: Re: Strange primary key constraint influence to grouping