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

[MySQL] sqlc.arg() does not work correctly in an AND NOT (...) clause. #3608

Open
tomtwinkle opened this issue Sep 13, 2024 · 0 comments
Open

Comments

@tomtwinkle
Copy link

Version

1.27.0

What happened?

The generated code is not what I expected.
Originally, the part specified by sqlc.arg() was ? but it is output as it is.

Expected Result

const listTests = `-- name: ListTests :many
SELECT id, created_at FROM tests
WHERE created_at >= ?
AND NOT (created_at = ? AND id <= ?)
ORDER BY created_at ASC
LIMIT ?
`

type ListTestsParams struct {
	ID []byte
	CreatedAt time.Time
	Limit     int32
}

Actual Result

const listTests = `-- name: ListTests :many
SELECT id, created_at FROM tests
WHERE created_at >= ?
AND NOT (created_at = sqlc.arg(created_at) AND id <= sqlc.arg(id))
ORDER BY created_at ASC
LIMIT ?
`

type ListTestsParams struct {
	CreatedAt time.Time
	Limit     int32
}

Relevant log output

No response

Database schema

CREATE TABLE `tests` (
  `id` binary(16) NOT NULL,
  `created_at` datetime(6) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `index_tests_1` (`created_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

SQL queries

-- name: ListTests :many
SELECT * FROM tests
WHERE created_at >= sqlc.arg(created_at)
AND NOT (created_at = sqlc.arg(created_at) AND id <= sqlc.arg(id))
ORDER BY created_at ASC
LIMIT ?;

Configuration

version: "2"
sql:
  - engine: "mysql"
    queries: "query.sql"
    schema: "schema.sql"
    gen:
      go:
        package: "sqlc"
        out: "sqlc"
        emit_prepared_queries: true
        emit_empty_slices: true
        emit_json_tags: false
        json_tags_id_uppercase: true
        emit_result_struct_pointers: true
        emit_methods_with_db_argument: false

Playground URL

No response

What operating system are you using?

macOS

What database engines are you using?

MySQL

What type of code are you generating?

Go

@tomtwinkle tomtwinkle added the bug Something isn't working label Sep 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant