Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQLServerDialect does not wrap TOP statement in parenthesis #2709

Closed
loicprieur opened this issue Mar 1, 2023 · 0 comments · Fixed by #2710
Closed

SQLServerDialect does not wrap TOP statement in parenthesis #2709

loicprieur opened this issue Mar 1, 2023 · 0 comments · Fixed by #2710

Comments

@loicprieur
Copy link
Contributor

Using .take(x) with a runtime value on MS SQL Server causes the query to fail.

Moreover parenthesis are recommended by Microsoft: https://learn.microsoft.com/en-us/sql/t-sql/queries/top-transact-sql?view=sql-server-ver16#compatibility-support

Version: 4.6.0
Module: quill-jdbc / quill-engine (not sure)
Database: mssqlserver

Expected behavior

Expected query to succeed and keep only the first x results (where x is take's parameter).

Actual behavior

query fails with:
com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near '@P0'

Steps to reproduce the behavior

val limit = 10
val q = quote {
   query[Person].take(lift(limit))
}

ctx.run(q)

Workaround

2 options:

  • drop and take which makes the dialect use the OFFSET FETCH syntax, which in turn requires the query to be sorted, and indexed.
  • Use a custom Dialect with the correct syntax around TOP parameter.

@getquill/maintainers

loicprieur pushed a commit to loicprieur/zio-quill that referenced this issue Mar 1, 2023
loicprieur pushed a commit to loicprieur/zio-quill that referenced this issue Mar 1, 2023
loicprieur added a commit to loicprieur/zio-quill that referenced this issue Mar 1, 2023
juliano added a commit that referenced this issue May 31, 2023
Co-authored-by: Juliano Alves <von.juliano@gmail.com>
joelsonoda pushed a commit to joelsonoda/zio-quill that referenced this issue Jun 27, 2023
…2710)

Co-authored-by: Juliano Alves <von.juliano@gmail.com>
jilen pushed a commit that referenced this issue Jun 11, 2024
Co-authored-by: Juliano Alves <von.juliano@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant