Skip to content

Conversation

andriygm
Copy link

@andriygm andriygm commented May 14, 2025

sqlc currently doesn't handle bound ORDER BY clauses in sqlite, nor does it have tests for this behavior. This PR attempts for rectify this. Closes #3788.

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. 🔧 golang labels May 14, 2025
@andriygm andriygm marked this pull request as draft May 14, 2025 14:46
@andriygm andriygm marked this pull request as ready for review May 14, 2025 15:50
@andriygm
Copy link
Author

currently, base behavior works but mixing params like so:

-- name: ListAuthorsColumnSortDirection :many SELECT * FROM authors WHERE id > ? ORDER BY CASE WHEN @order_by = 'asc' THEN name END ASC, CASE WHEN @order_by = 'desc' OR @order_by IS NULL THEN name END DESC;

produces this incorrect output (question marks in CASE clauses should instead be same variable)

-- name: ListAuthorsColumnSortDirection :many SELECT id, name, bio FROM authors WHERE id > ? ORDER BY CASE WHEN ? = 'asc' THEN name END ASC, CASE WHEN ? = 'desc' OR ? IS NULL THEN name END DESC

this can still be worked around by using named params in this case.

@andriygm andriygm changed the title Fix ORDER BY clause in sqlite Fix ORDER BY arg parsing in sqlite May 16, 2025
@ilikeorangutans
Copy link

How can we get this PR merged? I'm currently running into this issue :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files. 🔧 golang

2 participants