Re: ntile() throws ERROR when hashagg is false - Mailing list pgsql-hackers

From Andrew Gierth
Subject Re: ntile() throws ERROR when hashagg is false
Date
Msg-id 87efh9svy2.fsf@news-spur.riddles.org.uk
Whole thread Raw
In response to ntile() throws ERROR when hashagg is false  (Rajkumar Raghuwanshi <rajkumar.raghuwanshi@enterprisedb.com>)
Responses Re: ntile() throws ERROR when hashagg is false
List pgsql-hackers
>>>>> "Rajkumar" == Rajkumar Raghuwanshi <rajkumar.raghuwanshi@enterprisedb.com> writes:

 Rajkumar> Hi
 
 Rajkumar> ntile() throws ERROR when hashagg is false, test case given
 Rajkumar> below.

 Rajkumar> postgres=# create table foo (a int, b int, c text);
 Rajkumar> CREATE TABLE
 Rajkumar> postgres=# insert into foo select i%20, i%30, to_char(i%12, 'FM0000') from
 Rajkumar> generate_series(0, 36) i;
 Rajkumar> INSERT 0 37
 Rajkumar> postgres=# explain select ntile(a) OVER () from foo GROUP BY a;

This query isn't actually legal per the spec; the argument of ntile is
restricted to being a constant or parameter, so it can't change from row
to row. PG is more flexible, but that doesn't make the query any more
meaningful.

What I think pg is actually doing is taking the value of the ntile()
argument from the first row and using that for the whole partition.
In your example, enabling or disabling hashagg changes the order of the
input rows for the window function (since you've specified no ordering
in the window definition), and with hashagg off, you get the smallest
value of a first (which is 0 and thus an error).

-- 
Andrew (irc:RhodiumToad)


pgsql-hackers by date:

Previous
From: Thomas Munro
Date:
Subject: Re: WAL prefetch
Next
From: Konstantin Knizhnik
Date:
Subject: Re: WAL prefetch