Feature Request: Allow Syntax "FETCH FIRST n ROW(s) ONLY" in addition to LIMIT
(1.1) By ralf (ralfbertling) on 2023-04-24 16:25:58 edited from 1.0 [link] [source]
Edit: Made the point of the suggestion clearer (hopefully).
Hi, the most common (and as far as I know standard conforming) syntax to select the FIRST ROWS w.r.t. an ordering is (simplified): SELECT expressions FROM sources WHERE condition ... ORDER BY expressions [OFFSET numeric_expression] FETCH FIRST numeric_expression ROWS ONLY
SQLite currently only supports the propriatary syntax PostgreSQL introduced once upon a time. ... LIMIT numeric_expression [OFFSET numeric_expression]
(side note: Nobody should use offset to pagination https://use-the-index-luke.com/no-offset)
The statements would lead to identical results. It would just be easier to test SQL with SQLite and later on also use it with Oracle and SQL-Server. So this would only change the behavior of the parser.
This syntax is supported by most rdbms, so ist would be useful for interoperability if SQLite would also support this syntax. (Oracle, SQL Server*, PostgreSQL, DB2 all support FETCH FIRST ROW(S), *SQL Server only when combined with order by and offset, but using a literal value 0 can be used to prevend OFFSET's harm). MySQL and SQLite are the odd ones out on this. This happens to be the SQLite forum ;-)
Thanks for consindering!
(2) By Larry Brasfield (larrybr) on 2023-04-24 12:44:40 in reply to 1.0 [link] [source]
You should study the SELECT syntax, with particular attention paid to the LIMIT keyword and its effects.
(3.1) By ralf (ralfbertling) on 2023-04-24 16:35:50 edited from 3.0 in reply to 2 [source]
Thanks for the reply!
I am familiar with the select syntax. Probably I haven't made my point clear enough.
My request is to allow the standard syntax in addition to the propriatary syntax that would obviously stick around for compatibility reasons.
Edit: Added link to the postgresql documentation for the syntax
(4) By Holger J (holgerj) on 2023-04-24 16:35:32 in reply to 1.1 [link] [source]
I think this is basically a good idea, although it is just another syntax without any enhancement of functionality.
Therefore, I would suggest that also the syntax WITH TIES
in addition to ONLY
gets supported.
(5) By ralf (ralfbertling) on 2023-04-24 16:44:54 in reply to 4 [link] [source]
I most certainly wouldn't mind that.
Its more implementation work, so I was worried it could decrease the probability of any enhancement to request the broader enhancement.