You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by "Vova Vysotskyi (Jira)" <ji...@apache.org> on 2021/12/28 19:33:00 UTC

[jira] [Created] (CALCITE-4968) Calcite generates invalid MS SQL queries for the query with the LIMIT statement

Vova Vysotskyi created CALCITE-4968:
---------------------------------------

             Summary: Calcite generates invalid MS SQL queries for the query with the LIMIT statement
                 Key: CALCITE-4968
                 URL: https://issues.apache.org/jira/browse/CALCITE-4968
             Project: Calcite
          Issue Type: Bug
            Reporter: Vova Vysotskyi


Calcite converts the following query
{code:sql}
SELECT * FROM "employee" LIMIT 1
{code}
to the following one for {{MssqlSqlDialect}}:
{code:sql}
SELECT *
FROM [foodmart].[employee]
FETCH NEXT 1 ROWS ONLY
{code}
The issue is that MS SQL Server allows using {{FETCH}} (and {{OFFSET}}) statements only when {{ORDER BY}} is specified, so the query above fails.

One of the workarounds for this limitation is to insert {{ORDER BY (SELECT NULL)}} for the case when no actual {{ORDER BY}} statement is specified.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)