Re: FETCH FIRST clause PERCENT option

From: Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>
To: Surafel Temesgen <surafel3000(at)gmail(dot)com>
Cc: vik(dot)fearing(at)2ndquadrant(dot)com, Mark Dilger <hornschnorter(at)gmail(dot)com>, Andres Freund <andres(at)anarazel(dot)de>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: FETCH FIRST clause PERCENT option
Date: 2018-11-25 13:52:46
Message-ID: 871s79qnm1.fsf@news-spur.riddles.org.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

>>>>> "Surafel" == Surafel Temesgen <surafel3000(at)gmail(dot)com> writes:

Surafel> this is because fetch first values work with integer and it
Surafel> change fractional number to nearest integer number like select
Surafel> * from generate_series(1, 1000) fetch first 20.3 rows only; is
Surafel> not an error rather it return 20 rows.

31) The declared type of the <simple value specification> simply
contained in <fetch first percentage> shall be numeric.

Note that unlike <fetch first row count> there is no requirement for the
type to be _exact_ numeric or to have scale 0.

later:

ii) If <fetch first percentage> is specified, then let FFP be the
<simple value specification> simply contained in <fetch first
percentage>, and let LOCT be a <literal> whose value is OCT. Let
FFRC be the value of

CEILING ( FFP * LOCT / 100.0E0 )

NOTE 333 -- The percentage is computed using the number
of rows before removing the rows specified by <offset
row count>.

ceil(20.3 * 1000 / 100.0E0) is definitely 203, not 200.

--
Andrew.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Nikolay Shaplov 2018-11-25 14:49:42 Re: Add extension options to control TAP and isolation tests
Previous Message Andrew Dunstan 2018-11-25 13:12:16 Re: RHEL 8.0 build