Skip to content

Inferring columns from some CTE's is invalid #4198

@blanchardglen

Description

@blanchardglen

Version

1.28.0

What happened?

I have the following CTE in my queries.sql

WITH w_pending_sale_status as (
    select * from 
    (values ('SAVED'), ('IDLE'), ('IN PROGRESS'), ('HELD')) 
    as pending_sale_status(status)
)
SELECT status FROM w_pending_sale_status;

Once generated the go file's sql is this

WITH w_pending_sale_status as (
select  from 
    (values ('SAVED'), ('IDLE'), ('IN PROGRESS'), ('HELD')) 
    as pending_sale_status(status)
)
SELECT status FROM w_pending_sale_status;

Notice it is missing the * so that the error when execting from postgres is column status is not a valid column name

Relevant log output

NA

Database schema

SQL queries

-- name: SaleStatus :many
WITH w_pending_sale_status as (
    select * from 
    (values ('SAVED'), ('IDLE'), ('IN PROGRESS'), ('HELD')) 
    as pending_sale_status(status)
)
SELECT status FROM w_pending_sale_status;

Configuration

version: "2"
sql:
  - engine: "postgresql"
    queries: "db/queries"
    schema: "db/migrations"
    codegen:
    - plugin: golang
      out: "gen/db"
      options:
        package: "gendb"
        sql_package: "pgx/v5"
        overrides:
        - column: "transactions.amount"
          go_type:
            import: "github.com/shopspring/decimal"
            type: "Decimal"
            pointer: true
        - db_type: "pg_catalog.numeric"
          go_type: "github.com/shopspring/decimal.Decimal"
        - db_type: "pg_catalog.numeric"
          go_type: "github.com/shopspring/decimal.NullDecimal"
          nullable: true

Playground URL

No response

What operating system are you using?

Windows

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