Skip to content

[MSSQL] embedded SELECT TOP (N) query limit #424

@xeptore

Description

@xeptore

First of all, thanks for the effort. I'm using xo/dbtpl package specifically for generating Go code from raw SQL queries targeting a MSSQL database. However, I faced the following limitation/issue when wanted to generate code for the following simple query:

SELECT TOP (%%size int%%) * FROM Orders;

I try to generate code using the following command:

go run github.com/xo/dbtpl@latest \
  query \
  'ms://sa:pass@127.0.0.1:1433/db' < .query.sql \
  -M \
  -B \
  -U \
  -2 \
  -T RecentOrdersResult \
  -F RecentOrders

It returns the following error:

error: mssql: The number of rows provided for a TOP or FETCH clauses row count parameter must be an integer.
exit status 1

I circumvented this using OFFSET 0 ROWS FETCH NEXT %%size int%% ROWS ONLY, but there are performance improvements when TOP (N) syntax is used.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions