sqlc-dev / sqlc

Generate type-safe code from SQL
https://sqlc.dev
MIT License
13.37k stars 803 forks source link

Wierd field name when using function. #2647

Closed aca closed 1 year ago

aca commented 1 year ago

Version

1.20.0

What happened?

Generated query. GetAuthorParams should have field Name not Rpad.

const getAuthor = `-- name: GetAuthor :one
SELECT id, name, bio FROM authors WHERE name = RPAD($1,32) and bio = $2 LIMIT 1`

type GetAuthorParams struct {
    Rpad string
    Bio  sql.NullString
}

Relevant log output

No response

Database schema

-- Example queries for sqlc
CREATE TABLE authors (
  id   BIGSERIAL PRIMARY KEY,
  name text      NOT NULL,
  bio  text
);

SQL queries

-- name: GetAuthor :one
SELECT * FROM authors WHERE name = RPAD($1,32) and bio = $2 LIMIT 1;

Configuration

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

Playground URL

https://play.sqlc.dev/p/0ae261035f076a2afc9f7cb89cdacad020b8c6cb3a408963b9d579475a03cb82

What operating system are you using?

Linux, Windows, macOS

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

orisano commented 1 year ago

Please use named parameter instead. https://play.sqlc.dev/p/2c9e508800714c80b648ee83c772abd27025c7ebcc6e7948a7c606f85a40a018

aca commented 1 year ago

Didn't know that, thanks!