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

Поиск
Список
Период
Сортировка
От Henry Drexler
Тема Re: Why does aggregate query allow select of non-group by or aggregate values?
Дата
Msg-id CAAtgU9RNoFPTdtKDii9kCYkLQk7XTs9CACj2TPJsED_9PwxrCA@mail.gmail.com
обсуждение исходный текст
Ответ на Why does aggregate query allow select of non-group by or aggregate values?  (Jack Christensen <jackc@hylesanderson.edu>)
Список pgsql-general


On Fri, Dec 9, 2011 at 5:48 PM, Jack Christensen <jackc@hylesanderson.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@hylesanderson.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. 

В списке pgsql-general по дате отправления:

Предыдущее
От: Jack Christensen
Дата:
Сообщение: Why does aggregate query allow select of non-group by or aggregate values?
Следующее
От: "David Johnston"
Дата:
Сообщение: Re: Why does aggregate query allow select of non-group by or aggregate values?