Re: FETCH FIRST clause PERCENT option

From: Vik Fearing <vik(dot)fearing(at)2ndquadrant(dot)com>
To: Surafel Temesgen <surafel3000(at)gmail(dot)com>
Cc: Mark Dilger <hornschnorter(at)gmail(dot)com>, Andres Freund <andres(at)anarazel(dot)de>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, andrew(at)tao11(dot)riddles(dot)org(dot)uk
Subject: Re: FETCH FIRST clause PERCENT option
Date: 2018-11-25 12:05:23
Message-ID: 782a231d-47c3-78ee-10c6-a3853ef6c691@2ndquadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 25/11/2018 12:49, Surafel Temesgen wrote:
>
>
> On Sun, Nov 25, 2018 at 1:24 PM Vik Fearing <vik(dot)fearing(at)2ndquadrant(dot)com
> <mailto:vik(dot)fearing(at)2ndquadrant(dot)com>> wrote:
>
>
> Also, this query returns 210 rows instead of the expected 208:
>
>     select *
>     from generate_series(1, 1000)
>     fetch first 20.8 percent rows only
>
> this is because fetch first values work with integer and it change
> fractional number to nearest integer number like select * from
> generate_series(1, 1000) fetch first 20.3 rows only; is not an error
> rather it return 20 rows.

I don't see how this behavior is justified by reading the SQL standard.
Obviously only an integer number of rows is going to be returned, but
the percentage should be calculated correctly.

I assume you meant 200 rows there, but the correct number of rows to
return is 203 for that query. Please fix it.
--
Vik Fearing +33 6 46 75 15 36
http://2ndQuadrant.fr PostgreSQL : Expertise, Formation et Support

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Dunstan 2018-11-25 13:12:16 Re: RHEL 8.0 build
Previous Message Surafel Temesgen 2018-11-25 11:49:53 Re: FETCH FIRST clause PERCENT option