Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix ORDER BY arg parsing in sqlite #3962

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

Open
andriygm wants to merge 2 commits into sqlc-dev:main
base: main
Choose a base branch
Loading
from andriygm:fix-sqlite-order-by-args

Conversation

Copy link

@andriygm andriygm commented May 14, 2025
edited
Loading

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.

ElecTwix reacted with thumbs up emoji
@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
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
size:L This PR changes 100-499 lines, ignoring generated files. 🔧 golang
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Args in sqlite ORDER BY not respected
1 participant

AltStyle によって変換されたページ (->オリジナル) /