One neat feature, we can now omit extraneous fields on GROUP BY, as long as primary key is already there
create table person ( person_id serial not null primary key, firstname text not null, lastname text not null, address text not null ); create table visit ( visit_id serial not null primary key, person_id int not null references person(person_id), url text not null ); select p.person_id, p.firstname, p.lastname, p.address, count(*) from person p join visit v on p.person_id = v.person_id group by p.person_id -- ,p.firstname, p.lastname, p.address; -- omitting other fields is now possible on 9.1
And it's still the same disciplined Postgresql
select p.firstname, p.lastname, count(*) from person p join visit v on p.person_id = v.person_id group by p.firstname -- this is not allowed, it's confusing which lastname to pick
No comments:
Post a Comment