Re: sql2008 diff sql2003 - Mailing list pgsql-hackers

From Andrew Gierth
Subject Re: sql2008 diff sql2003
Date
Msg-id 87ej3ulfho.fsf@news-spur.riddles.org.uk
Whole thread Raw
In response to sql2008 diff sql2003  ("Pavel Stehule" <pavel.stehule@gmail.com>)
Responses Re: sql2008 diff sql2003  (Alvaro Herrera <alvherre@alvh.no-ip.org>)
List pgsql-hackers
>>>>> "Alvaro" == Alvaro Herrera <alvherre@commandprompt.com> writes:
Alvaro> Wow, this is really horrid:
Alvaro>  # F856 through F859: FETCH FIRST clause in subqueries,Alvaro>  views, and query expressions. The SQL:2008
syntaxforAlvaro>  restricting the rows of a result set is FETCH FIRST, ratherAlvaro>  than Microsoft SQL Server’s
SELECTTOP N equivalent whichAlvaro>  SQL Anywhere supports presently.
 
Alvaro> This means we have to support stuff like
Alvaro> declare foo cursor for select * from lists;Alvaro> select * from (fetch first from foo) as bar;

No, that's wrong.

The new syntax is:

<query expression> ::= [ <with clause> ] <query expression body>     [ <order by clause> ] [ <result offset clause> ] [
<fetchfirst clause> ]
 

<result offset clause> ::= OFFSET <offset row count> { ROW | ROWS }

<fetch first clause> ::= FETCH { FIRST | NEXT } [ <fetch first row count> ] { ROW | ROWS } ONLY

so it's like this:

select * from foo order by bar offset 5 rows fetch first 10 rows only;

(nothing that I can see assigns any semantics to FIRST vs NEXT, they seem
to do the same thing)

-- 
Andrew (irc:RhodiumToad)


pgsql-hackers by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: sql2008 diff sql2003
Next
From: "Brendan Jurd"
Date:
Subject: Re: [PATCHES] to_date() validation