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

Incorrect query builder syntax for TOP + DISTINCT on MS SQL #858

Open
severedsea opened this issue Nov 5, 2020 · 0 comments
Open

Incorrect query builder syntax for TOP + DISTINCT on MS SQL #858

severedsea opened this issue Nov 5, 2020 · 0 comments

Comments

@severedsea
Copy link
Contributor

severedsea commented Nov 5, 2020

If you're having a generation problem please answer these questions before submitting your issue. Thanks!

What version of SQLBoiler are you using (sqlboiler --version)?

v4.2.0

What is your database and version (eg. Postgresql 10)

Microsoft SQL Server 2019

If this happened at generation time what was the full SQLBoiler command you used to generate your models? (if not applicable leave blank)

If this happened at runtime what code produced the issue? (if not applicable leave blank)

results, err := models.SomeTables(
	qm.Distinct(models.TableNames.SomeTable+".*"),
	qm.Limit(10),
).All(ctx, tx)

What is the output of the command above with the -d flag added to it? (Provided you are comfortable sharing this, it contains a blueprint of your schema)

SELECT  TOP (10) DISTINCT some_table.* FROM some_table;
mssql: Incorrect syntax near the keyword 'DISTINCT'.
        	            	bind failed to execute query

Please provide a relevant database schema so we can replicate your issue (Provided you are comfortable sharing this)

Further information. What did you do, what did you expect?

The query builders construct query by adding the TOP statement before the DISTINCT (https://github.com/volatiletech/sqlboiler/blob/master/queries/query_builders.go#L53-L76)

Valid syntax (at least on MS SQL) is SELECT DISTINCT TOP (10) ... https://stackoverflow.com/a/37642799

Note: Reason why there's a DISTINCT is because I have joins for conditional statements on the query.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants