Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-4968

Calcite generates invalid MS SQL queries for the query with the LIMIT statement

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.30.0
    • None

    Description

      Calcite converts the following query

      SELECT * FROM "employee" LIMIT 1
      

      to the following one for MssqlSqlDialect:

      SELECT *
      FROM [foodmart].[employee]
      FETCH NEXT 1 ROWS ONLY
      

      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.

      Attachments

        Issue Links

          Activity

            People

              volodymyr Vova Vysotskyi
              volodymyr Vova Vysotskyi
              Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 40m
                  40m