sqlc icon indicating copy to clipboard operation
sqlc copied to clipboard

Query and column overrides use different types for the same underlying database type

Open kyleconroy opened this issue 2 years ago • 1 comments

  - db_type: "pg_catalog.numeric"
    nullable: false                          
    go_type:
      import: "yapi/types"
      type: "Decimal"
  - db_type: "pg_catalog.numeric"
    nullable: true                          
    go_type:
      import: "yapi/types"
      type: "Decimal"        

this was generating model ok, but not the queries. I fixed it by duplicating the above for numeric type but without the schema

  - db_type: "numeric"
    nullable: false                          
    go_type:
      import: "yapi/types"
      type: "Decimal"
  - db_type: "numeric"
    nullable: true                          
    go_type:
      import: "yapi/types"
      type: "Decimal"   

The issue appears in gen.go file here

structs := buildStructs(req, options)
queries, err := buildQueries(req, options, structs)

buildStructs works off schema.Tables, while buildQueries off req.Queries.Params

These functions need to be aligned to use schema data from the same source.

I'll just stick with my workaround for now, as I don't have time to fix this - it appears some significant changes may be required here.

This misalignment is likely to cause other issues, I'm sure.

Originally posted by @shkvoretz in https://github.com/sqlc-dev/sqlc/issues/3005#issuecomment-1850261768

kyleconroy avatar Dec 15 '23 16:12 kyleconroy

@shkvortez I can't reproduce this behavior in the playground. Can you take a look at the example and help me out?

kyleconroy avatar Dec 15 '23 17:12 kyleconroy