pingcap / parser

A MySQL Compatible SQL Parser
Apache License 2.0
1.4k stars 490 forks source link

Support the SQL:2008 Standard `OFFSET m ROWS FETCH FIRST n ROWS` clause #973

Open kennytm opened 4 years ago

kennytm commented 4 years ago

Feature Request

Is your feature request related to a problem? Please describe:

SQL:2008 introduced the FETCH FIRST clause to unify the LIMIT feature with varying syntax among all RDBMS (CD 9075-2:201X §7.16/6–7). This feature is supported in PostgreSQL, DB2 and Oracle. Users migrating from outside MySQL may find it more natural to use the standard syntax than LIMIT. (see also https://bugs.mysql.com/bug.php?id=78929.)

Describe the feature you'd like:

Parse the clause:

[ OFFSET m { ROW | ROWS } ]
[ FETCH { FIRST | NEXT } [ n ] { ROW | ROWS } ONLY ]

as equivalent to

LIMIT n OFFSET m

(if n is missing it default to 1)

(FIRST and NEXT are synonyms)

Describe alternatives you've considered:

Don't support it.

Teachability, Documentation, Adoption, Migration Strategy:

bb7133 commented 4 years ago

Sounds an interesting feature :)

time-and-fate commented 4 years ago

After discussion with kennytm, I'll only support FETCH { FIRST | NEXT } [ n ] { ROW | ROWS } ONLY part in #985 for now because it seems very complicated to support the [ OFFSET m { ROW | ROWS } ] part.