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

Unsigned types not present in query parameters #2432

Closed
Icikowski opened this issue Jul 11, 2023 · 0 comments · Fixed by #2522
Closed

Unsigned types not present in query parameters #2432

Icikowski opened this issue Jul 11, 2023 · 0 comments · Fixed by #2522
Labels
bug Something isn't working triage New issues that hasn't been reviewed

Comments

@Icikowski
Copy link

Version

Other

What happened?

sqlc version: 1.19.0

When generating code for an SQL query against a table with fields marked as UNSIGNED, the query arguments should also be unsigned. The currently generated code for the query relies on signed types, which is not the desired behavior.

In the case presented below, the following code is generated:

type UpsertMappingParams struct {
	LeftID  int64
	RightID int64
}

The expected and correct result should be:

type UpsertMappingParams struct {
	LeftID  uint64
	RightID uint64
}

Relevant log output

No response

Database schema

CREATE TABLE IF NOT EXISTS `mappings` (
  `id` BIGINT(20) UNSIGNED NOT NULL,
  `left_id` BIGINT(20) UNSIGNED NOT NULL,
  `right_id` BIGINT(20) UNSIGNED NOT NULL,
  PRIMARY KEY (`left_id`, `right_id`),
  UNIQUE INDEX `id_UNIQUE` (`id` ASC) VISIBLE,
  INDEX `fk_left_id_idx` (`left_id` ASC) VISIBLE,
  INDEX `fk_right_id_idx` (`right_id` ASC) VISIBLE
);

SQL queries

-- name: UpsertMapping :exec
INSERT INTO
    mappings (left_id, right_id)
VALUES
    (?, ?)
ON DUPLICATE KEY UPDATE
    id = id;

Configuration

{
  "version": "1",
  "packages": [
    {
      "path": "db",
      "engine": "mysql",
      "schema": "query.sql",
      "queries": "query.sql"
    }
  ]
}

Playground URL

https://play.sqlc.dev/p/6316120fffa5029678410f26691f24670d912069e1345473c95c1f0d6825db6a

What operating system are you using?

Linux

What database engines are you using?

MySQL

What type of code are you generating?

Go

@Icikowski Icikowski added bug Something isn't working triage New issues that hasn't been reviewed labels Jul 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage New issues that hasn't been reviewed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant