Skip to content

Commit dff9bc3

Browse files
fix: move ORDER BY out of create_temp_table query for T-SQL compatibility
T-SQL forbids ORDER BY in views/subqueries/CTEs unless TOP or OFFSET is also specified. The fabric__create_temp_table uses a VIEW workaround, so ORDER BY must be in the final SELECT, not in the materialised query. Co-Authored-By: Itamar Hartstein <haritamar@gmail.com>
1 parent f51dfc9 commit dff9bc3

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

elementary/monitor/dbt_project/macros/get_test_results.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,16 @@
177177
test_results.result_rows
178178
from {{ ordered_relation }} as test_results
179179
where test_results.invocations_rank_index <= {{ invocations_per_test }}
180-
order by test_results.elementary_unique_id, test_results.invocations_rank_index desc
181180
{%- endset -%}
182181

183182
{% set final_relation = elementary.create_temp_table(elementary_database, elementary_schema, 'final_test_results', select_test_results) %}
184183

185184
{% set test_results = [] %}
186185

186+
{# ORDER BY must be here, not inside create_temp_table — T-SQL forbids ORDER BY in views/subqueries without TOP #}
187187
{% set test_results_agate_sql %}
188188
select * from {{ final_relation }}
189+
order by elementary_unique_id, invocations_rank_index desc
189190
{% endset %}
190191

191192
{% set valid_ids_query %}

0 commit comments

Comments
 (0)