Skip to content

Column type overrides lost when renaming a parameter #1864

@haines

Description

@haines

Version

1.15.0

What happened?

When a type override is defined for a column, it only applies to parameters if they are positional or named the same as the column itself.

In the example below, I expected to generate

func (q *Queries) Renamed(ctx context.Context, userEmail user.Email) (user.ID, error)

but with a named parameter I got

func (q *Queries) Renamed(ctx context.Context, userEmail string) (user.ID, error)

unless the parameter was named email (which matches the inferred name, so isn't very useful!).

Relevant log output

No response

Database schema

CREATE TABLE users (
  id bigserial PRIMARY KEY,
  email text NOT NULL CONSTRAINT unique_email UNIQUE
);

SQL queries

-- name: Renamed :one
SELECT id
FROM users
WHERE email = @user_email;

Configuration

{
  "version": "2",
  "sql": [
    {
      "engine": "postgresql",
      "schema": "query.sql",
      "queries": "query.sql",
      "gen": {
        "go": {
          "out": "db",
          "overrides": [
            {
              "column": "users.id",
              "go_type": "example.com/user.ID"
            },
            {
              "column": "users.email",
              "go_type": "example.com/user.Email"
            }
          ]
        }
      }
    }
  ]
}

Playground URL

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

What operating system are you using?

macOS

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions