Distinct and limit (top) with mssql #593

Closed
opened 2017-05-28 18:30:14 +00:00 by 22222 · 2 comments
22222 commented 2017-05-28 18:30:14 +00:00 (Migrated from github.com)

In gogs gogits/gogs#4419, using Distinct and Limit together in MSSQL results in a syntax error. I think that problem might be coming from xorm? Possibly from a Sprintf in statement.go.

Currently the generated SQL looks like this:

SELECT TOP 10 DISTINCT ...

It should have DISTINCT before TOP, like this:

SELECT DISTINCT TOP 10 ...
In gogs gogits/gogs#4419, using `Distinct` and `Limit` together in MSSQL results in a syntax error. I think that problem might be coming from xorm? Possibly from a [Sprintf in statement.go](https://github.com/go-xorm/xorm/blob/6b6721cccc0015ea5275fdb3ae233872e1f654df/statement.go#L1281). Currently the generated SQL looks like this: ```sql SELECT TOP 10 DISTINCT ... ``` It should have `DISTINCT` before `TOP`, like this: ```sql SELECT DISTINCT TOP 10 ... ```

@22222 please confirm that #596 fixed this issue.

@22222 please confirm that #596 fixed this issue.
22222 commented 2017-05-31 00:05:23 +00:00 (Migrated from github.com)

Looks good to me. I tested with a local copy of gogs (using mssql), and the error stopped after updating to the version of xorm with this fix (the lunny/fix_mssql_top_distinct branch).

Thanks for getting a fix in so quickly.

Looks good to me. I tested with a local copy of gogs (using mssql), and the error stopped after updating to the version of xorm with this fix (the `lunny/fix_mssql_top_distinct` branch). Thanks for getting a fix in so quickly.
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: xorm/xorm#593
No description provided.