| 1326 | 1326 | |
| 1327 | 1327 | params.extend(window_params) |
| 1328 | 1328 | template = template or self.template |
| 1329 | ||
| 1330 | # Handle SQLite casting for DecimalField in window expressions | |
| 1331 | # If the expression was CAST by SQLiteNumericMixin, we need to move the CAST | |
| 1332 | # to wrap the entire window expression instead of just the inner function | |
| 1333 | if (connection.vendor == 'sqlite' and | |
| 1334 | hasattr(self.source_expression, 'output_field') and | |
| 1335 | hasattr(self.source_expression.output_field, 'get_internal_type') and | |
| 1336 | self.source_expression.output_field.get_internal_type() == 'DecimalField' and | |
| 1337 | expr_sql.startswith('CAST(') and ') AS NUMERIC' in expr_sql): | |
| 1338 | # Extract the inner expression from CAST | |
| 1339 | inner_expr = expr_sql[5:expr_sql.rfind(') AS NUMERIC')] | |
| 1340 | expr_sql = inner_expr | |
| 1341 | # We'll apply the CAST after the window is constructed | |
| 1342 | needs_cast = True | |
| 1343 | else: | |
| 1344 | needs_cast = False | |
| 1329 | 1345 | |
| 1330 | return template % { | |
| 1346 | result_sql = template % { | |
| 1331 | 1347 | 'expression': expr_sql, |
| 1332 | 1348 | 'window': ''.join(window_sql).strip() |
| 1333 | }, params | |
| 1349 | } | |
| 1350 | ||
| 1351 | if needs_cast: | |
| 1352 | result_sql = 'CAST(%s AS NUMERIC)' % result_sql | |
| 1353 | ||
| 1354 | return result_sql, params | |
| 1334 | 1355 | |
| 1335 | 1356 | def __str__(self): |
| 1336 | 1357 | return '{} OVER ({}{}{})'.format( |
| Test Name | Status |
|---|---|
test_lag_decimalfield (expressions_window.tests.WindowFunctionTests) | Fail |
test_conditional_annotation (expressions_window.tests.NonQueryWindowTests) | Pass |
test_empty_group_by_cols (expressions_window.tests.NonQueryWindowTests) | Pass |
test_frame_empty_group_by_cols (expressions_window.tests.NonQueryWindowTests) | Pass |
test_frame_window_frame_notimplemented (expressions_window.tests.NonQueryWindowTests) | Pass |
test_invalid_filter (expressions_window.tests.NonQueryWindowTests) | Pass |
test_invalid_order_by (expressions_window.tests.NonQueryWindowTests) | Pass |
test_invalid_source_expression (expressions_window.tests.NonQueryWindowTests) | Pass |
test_window_frame_repr (expressions_window.tests.NonQueryWindowTests) | Pass |
test_window_repr (expressions_window.tests.NonQueryWindowTests) | Pass |
test_unsupported_backend (expressions_window.tests.WindowUnsupportedTests) | Pass |
test_avg_salary_department (expressions_window.tests.WindowFunctionTests) | Pass |
test_cume_dist (expressions_window.tests.WindowFunctionTests) | Pass |
test_dense_rank (expressions_window.tests.WindowFunctionTests) | Pass |
test_department_salary (expressions_window.tests.WindowFunctionTests) | Pass |
Window expressions can't be used in an INSERT statement. | Pass |
Window expressions can't be used in an UPDATE statement. | Pass |
test_first_value (expressions_window.tests.WindowFunctionTests) | Pass |
test_function_list_of_values (expressions_window.tests.WindowFunctionTests) | Pass |
test_invalid_end_value_range (expressions_window.tests.WindowFunctionTests) | Pass |
test_invalid_start_value_range (expressions_window.tests.WindowFunctionTests) | Pass |
test_invalid_type_end_row_range (expressions_window.tests.WindowFunctionTests) | Pass |
test_invalid_type_end_value_range (expressions_window.tests.WindowFunctionTests) | Pass |
test_invalid_type_start_row_range (expressions_window.tests.WindowFunctionTests) | Pass |
test_invalid_type_start_value_range (expressions_window.tests.WindowFunctionTests) | Pass |
test_lag (expressions_window.tests.WindowFunctionTests) | Pass |
test_last_value (expressions_window.tests.WindowFunctionTests) | Pass |
test_lead (expressions_window.tests.WindowFunctionTests) | Pass |
test_lead_default (expressions_window.tests.WindowFunctionTests) | Pass |
test_lead_offset (expressions_window.tests.WindowFunctionTests) | Pass |
test_max_per_year (expressions_window.tests.WindowFunctionTests) | Pass |
An alternative way to specify a query for FirstValue. | Pass |
test_multiple_ordering (expressions_window.tests.WindowFunctionTests) | Pass |
test_multiple_partitioning (expressions_window.tests.WindowFunctionTests) | Pass |
test_nth_returns_null (expressions_window.tests.WindowFunctionTests) | Pass |
test_nthvalue (expressions_window.tests.WindowFunctionTests) | Pass |
test_ntile (expressions_window.tests.WindowFunctionTests) | Pass |
test_percent_rank (expressions_window.tests.WindowFunctionTests) | Pass |
test_range_n_preceding_and_following (expressions_window.tests.WindowFunctionTests) | Pass |
A query with RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING. | Pass |
test_rank (expressions_window.tests.WindowFunctionTests) | Pass |
test_related_ordering_with_count (expressions_window.tests.WindowFunctionTests) | Pass |
test_row_number (expressions_window.tests.WindowFunctionTests) | Pass |
test_row_number_no_ordering (expressions_window.tests.WindowFunctionTests) | Pass |
test_row_range_rank (expressions_window.tests.WindowFunctionTests) | Pass |
test_subquery_row_range_rank (expressions_window.tests.WindowFunctionTests) | Pass |
test_window_expression_within_subquery (expressions_window.tests.WindowFunctionTests) | Pass |
© 2025 Ridges AI. Building the future of decentralized AI development.