Re: sql2008 diff sql2003

Lists: pgsql-hackers
From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: "PostgreSQL-development Hackers" <pgsql-hackers(at)postgresql(dot)org>
Subject: sql2008 diff sql2003
Date: 2008-09-08 16:38:18
Message-ID: 162867790809080938q7f60359g4454c27210512546@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: PostgreSQL-development Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: sql2008 diff sql2003
Date: 2008-09-08 17:02:52
Message-ID: 20080908170252.GE4411@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Pavel Stehule escribió:
> Hello
>
> I found one usefull article
> http://iablog.sybase.com/paulley/2008/07/sql2008-now-an-approved-iso-international-standard/

Wow, this is really horrid:

# F856 through F859: FETCH FIRST clause in subqueries, views,
and query expressions. The SQL:2008 syntax for restricting the
rows of a result set is FETCH FIRST, rather than Microsoft SQL
Server’s SELECT TOP N equivalent which SQL Anywhere supports
presently.

This means we have to support stuff like

declare foo cursor for select * from lists;
select * from (fetch first from foo) as bar;

(I wonder why didn't they use FETCH NEXT instead. As is, it seems a bit
cumbersome to use.)

--
Alvaro Herrera http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support


From: Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: sql2008 diff sql2003
Date: 2008-09-08 17:22:27
Message-ID: 87ej3ulfho.fsf@news-spur.riddles.org.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

>>>>> "Alvaro" == Alvaro Herrera <alvherre(at)commandprompt(dot)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 syntax for
Alvaro> restricting the rows of a result set is FETCH FIRST, rather
Alvaro> than Microsoft SQL Server’s SELECT TOP N equivalent which
Alvaro> 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> ] [ <fetch first 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)


From: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>
Cc: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: sql2008 diff sql2003
Date: 2008-09-09 02:03:07
Message-ID: 20080909020307.GN4411@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Andrew Gierth wrote:

> 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.

[...]

> so it's like this:
>
> select * from foo order by bar offset 5 rows fetch first 10 rows only;

Oh, I see -- it's just a cumbersome way to have our LIMIT clause.
What's the "ONLY" for?

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

I was actually thinking that you'd be able to open a cursor and then
invoke the query repeatedly. With FETCH FIRST it wouldn't work, because
every repetition would get the same rows, but with FETCH NEXT it'd give
you a paginated query.

It seems a lot less useful this way.

--
Alvaro Herrera Valdivia, Chile ICBM: S 39º 48' 55.3", W 73º 15' 24.7"
"I dream about dreams about dreams", sang the nightingale
under the pale moon (Sandman)


From: Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>
To: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
Cc: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: sql2008 diff sql2003
Date: 2008-09-09 02:16:37
Message-ID: 87r67uhxmi.fsf@news-spur.riddles.org.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

>>>>> "Alvaro" == Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org> writes:

>> so it's like this:
>>
>> select * from foo order by bar offset 5 rows fetch first 10 rows only;

Alvaro> Oh, I see -- it's just a cumbersome way to have our LIMIT
Alvaro> clause. What's the "ONLY" for?

It seems to be just a mandatory noise word.

--
Andrew.