Skip to content

sqlite WHERE ... AND x BETWEEN ? AND ? not generating the BETWEEN part as code #3974

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
jxsl13 opened this issue May 23, 2025 · 0 comments
Labels
📚 sqlite bug Something isn't working 🔧 golang

Comments

@jxsl13
Copy link

jxsl13 commented May 23, 2025

Version

1.29.0

What happened?

When the BETWEEN is preceeded by a WHERE, then the generation works as expected.
Adding the BETWEEN after an AND makes the generator completely ignore the parameters/placeholders used in that BETWEEN ? AND ?.

The bug is reproduced in this small repository:
https://github.com/jxsl13/sqlc-sqlite-between-test

Execute make generate in order to trigger the generation again.

Relevant log output

Database schema

CREATE TABLE IF NOT EXISTS test (
    id INTEGER PRIMARY KEY,
    name TEXT NOT NULL
);

SQL queries

-- name: QueryBetweenBroken :many
SELECT id FROM test
WHERE name = ?
AND id BETWEEN ? AND ?;

-- name: QueryBetweenNamedBroken :many
SELECT id FROM test
WHERE name = :name
AND id BETWEEN :min AND :max;

-- name: QueryBetweenWorking :many
SELECT id FROM test
WHERE id BETWEEN ? AND ?
AND name = ?;

-- name: QueryBetweenNamedWorking :many
SELECT id FROM test
WHERE id BETWEEN :min AND :max
AND name = :name;

Configuration

version: "2"
sql:
  - engine: "sqlite"
    queries: [
      "queries/test.sql"
    ]
    schema: [
      "migrations",
    ]
    gen:
      go:
        sql_package: "database/sql"
        package: "sqlc"
        out: "sqlc"
        overrides: []

        emit_db_tags: true
        emit_prepared_queries: true
        emit_empty_slices: true
        emit_enum_valid_method: true
        emit_pointers_for_null_types: true
        emit_all_enum_values: true

Playground URL

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

What operating system are you using?

macOS

What database engines are you using?

SQLite

What type of code are you generating?

Go

@jxsl13 jxsl13 added the bug Something isn't working label May 23, 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