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

get_limit_subquery() does not work with queries containing CTEs #228

Closed
dataders opened this issue Mar 29, 2024 · 1 comment · Fixed by #230
Closed

get_limit_subquery() does not work with queries containing CTEs #228

dataders opened this issue Mar 29, 2024 · 1 comment · Fixed by #230

Comments

@dataders
Copy link
Contributor

synapse__get_limit_subquery() wraps provided SQL string (sql) into a Subquery. If the subquery has a CTE, the SQL output by synapse__get_limit_subquery will throw the below error because CTEs are not supported within subqueries

('42000', "[42000] [Microsoft]
[ODBC Driver 18 for SQL Server][SQL Server]
Parse error at line: 9, column: 5:
Incorrect syntax near 'ID'. (103010) (SQLExecDirectW)")

This is especially a problem with the dbt Cloud IDE which will, by default, always try to only fetch the first 500 rows when previewing and compiling models.

I thought at first that fabric__get_limit_subquery() would work, but OFFSET is not supported in Synapse.

code in question

{# Synapse doesnt support ANSI LIMIT clause #}
{% macro synapse__get_limit_subquery_sql(sql, limit) %}
select top {{ limit }} *
from (
{{ sql }}
) as model_limit_subq
{% endmacro %}

@dataders
Copy link
Contributor Author

resolved by: #230

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