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

Args in sqlite ORDER BY not respected #3788

Open
bmpender opened this issue Jan 14, 2025 · 0 comments
Open

Args in sqlite ORDER BY not respected #3788

bmpender opened this issue Jan 14, 2025 · 0 comments
Labels
📚 sqlite bug Something isn't working 🔧 golang

Comments

@bmpender
Copy link

Version

1.27.0

What happened?

Similarly to #3113
The postgres generator supports variables in the ORDER BY, but sqlite does not.

CREATE TABLE authors (
  id int PRIMARY KEY
);
-- name: GetAuthor :one
SELECT * FROM authors
WHERE id = @id
ORDER BY @order_by;
const getAuthor = `-- name: GetAuthor :one
SELECT id FROM authors
WHERE id = ?1
ORDER BY @order_by
`

func (q *Queries) GetAuthor(ctx context.Context, id int64) (int64, error) {
	row := q.db.QueryRowContext(ctx, getAuthor, id)
	err := row.Scan(&id)
	return id, err
}

Playground link is to 1.25.0, but this is happening locally on 1.27.0 as well. Changing only the engine value to postgresql results in the expected output for postgresql. But the same is not reflected in sqlite.

Relevant log output

Database schema

CREATE TABLE authors (
  id int PRIMARY KEY
);

SQL queries

-- name: GetAuthor :one
SELECT * FROM authors
WHERE id = @id
ORDER BY @order_by;

Configuration

{
  "version": "2",
  "sql": [{
    "schema": "schema.sql",
    "queries": "query.sql",
    "engine": "sqlite",
    "gen": {
      "go": {
        "out": "db"
      }
    }
  }]
}

Playground URL

https://play.sqlc.dev/p/a0947e011d5ec187db7c502d1044c9eb10d6a2f9f5c6d44f166b23a2fa6c5f07

What operating system are you using?

macOS

What database engines are you using?

SQLite

What type of code are you generating?

Go

@bmpender bmpender added the bug Something isn't working label Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📚 sqlite bug Something isn't working 🔧 golang
Projects
None yet
Development

No branches or pull requests

1 participant