question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Compatibility with limit for SQL Server

See original GitHub issue

When query is passed to SQL Server for execution, it includes “limit 200” on the query. However, SQL Server does not like this syntax since T-SQL is not postgres compatible.

It looks like limit is attached here: dbtCommandFactory.ts

try:
    import decimal
    import json
    import re
    import sys
    import traceback
    import orjson
    from dbt_osmosis.core.osmosis import DbtOsmosis
    runner = DbtOsmosis(
        project_dir=r"${projectRoot.fsPath.replace(/"/g, '\\"')}",
        target=r"${target.replace(/"/g, '\\"')}",
    )
    query = """${sql.replace(/"/g, '\\"')}"""
    query_with_limit = f"select * from ({query}) as osmosis_query **limit ${limit}**"
    result = runner.execute_sql(query_with_limit)
except Exception as exc:
    eprint(json_dumps({"message": str(exc), "data": traceback.format_exc()}))
    sys.exit(-1)

The fix for SQL Server is detecting when the adapter type is SQL Server and passing the following syntax:

query_with_limit =  f"select top ${limit} * from ({query}) as osmosis_query "

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
matsonjcommented, Sep 27, 2022

its the little things…

image
1reaction
mdesmetcommented, Sep 27, 2022

You should use

"dbt.queryTemplate": "select top {limit} * from ({query}) as osmosis_query"
Read more comments on GitHub >

github_iconTop Results From Across the Web

Maximum capacity specifications for SQL Server
This article shows maximum sizes and numbers of various objects defined in SQL Server components, along with additional information.
Read more >
Equivalent of LIMIT and OFFSET for SQL Server?
Limit with offset to select 11 to 20 rows in SQL Server: SELECT email FROM emailTable WHERE user_id=3 ORDER BY Id OFFSET ...
Read more >
SQL Limit: A Beginner's Guide % - Career Karma
The LIMIT clause is only compatible with the SQL SELECT statement. You cannot use a LIMIT clause on an SQL UPDATE statement, for...
Read more >
How to Limit Rows in a SQL Server? - GeeksforGeeks
LIMIT syntax works in MYSQL. In the Microsoft database, we use the below syntax (TOP which works similar to LIMIT in MYSQL) ...
Read more >
Using the SQL Limit Clause - YouTube
Learn how to use the SQL Limit Clause to limit the results returned from the MySQL database. This video is from my online...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found