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

Type override not working on array #3716

Open
dcrystalj opened this issue Nov 21, 2024 · 2 comments
Open

Type override not working on array #3716

dcrystalj opened this issue Nov 21, 2024 · 2 comments
Labels

Comments

@dcrystalj
Copy link

Version

1.27.0

What happened?

When overriding int8 to uint it is not respected when using syntax like .... _id = ANY($1::int8[]);
Generated function creates int64 parameter instead of uint.

Relevant log output

No response

Database schema

No response

SQL queries

SELECT *
FROM page
WHERE internal_id = ANY($1::int8[]);

Configuration

{
  "version": "2",
  "sql": [
    {
      "engine": "postgresql",
      "schema": "query.sql",
      "queries": "query.sql",
      "gen": {
      	"go": {
          "package": "db",
          "out": "db",
          "sql_package": "pgx/v5",
          "overrides": [
          	{
              "db_type": "pg_catalog.int8",
              "go_type": {
                "type": "uint"
              }
           }
          ]
        }
      }
    }
  ]
}

Playground URL

https://play.sqlc.dev/p/3c687ce27bb56bf8c536047234a748c6a17e283475e00516c8df113d0f9fd45e

What operating system are you using?

macOS

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

@dcrystalj dcrystalj added the bug Something isn't working label Nov 21, 2024
@travikk
Copy link

travikk commented Nov 23, 2024

Facing very similar issue, where a param to my query is an array of values.

SELECT * FROM events WHERE event_type = ANY($1::SMALLINT[]);

In my case, I have a Go type that extends int16 as a form to create an enum in my codebase.

type EventType int16

const (
...
)

I want to be able to pass EventType around instead of int16 to the queries, so that I don't need to do casting allover the place.
While this works perfectly fine for when param/column is a single value, it doesn't work correctly for an array as illustrated above, because in the query itself we're telling SQLC to use smallint (int16) instead.

While it is possible to create an override for a smallint so that it maps to EventType, that would map all uses of smallint to EventType which is not what I want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants
@travikk @dcrystalj and others