Re: Why does aggregate query allow select of non-group by or aggregate values?

From: Henry Drexler <alonup8tb(at)gmail(dot)com>
To: Jack Christensen <jackc(at)hylesanderson(dot)edu>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Why does aggregate query allow select of non-group by or aggregate values?
Date: 2011-12-09 22:51:54
Message-ID: CAAtgU9RNoFPTdtKDii9kCYkLQk7XTs9CACj2TPJsED_9PwxrCA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, Dec 9, 2011 at 5:48 PM, Jack Christensen <jackc(at)hylesanderson(dot)edu>wrote:

> CREATE TABLE people(
> id serial PRIMARY KEY,
> name varchar NOT NULL
> );
>
> INSERT INTO people(name) VALUES('Adam'), ('Adam'), ('Adam'), ('Bill'),
> ('Sam'), ('Joe'), ('Joe');
>
> SELECT name, count(*), random()
> FROM people
> GROUP BY name;
>
>
> I would expect this query to cause an error because of random(). I ran
> into this using an array produced by a subquery as a column in the select
> of an aggregate query, but I was able to boil it down to this contrived
> example. Shouldn't any expression that is not in the group by or an
> aggregate function be rejected?
>
> What am I not understanding?
>
> Thanks.
>
> --
> Jack Christensen
> jackc(at)hylesanderson(dot)edu
>
>
I don't know the answer, but I would guess that as random() is not known
before hand , it has no reason being in the grouped by.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message David Johnston 2011-12-09 22:57:39 Re: Why does aggregate query allow select of non-group by or aggregate values?
Previous Message Jack Christensen 2011-12-09 22:48:00 Why does aggregate query allow select of non-group by or aggregate values?