Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Inferring columns from some CTE's is invalid #4198

Open

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

Activity

  1. added
    bug
    on Nov 28, 2025
  2. blanchardglen commented on Dec 1, 2025

    @blanchardglen
    Author

    A workaround for now is to use this CTE instead

    WITH w_pending_sale_status as (
    select unnest(ARRAY['SAVED', 'IDLE', 'IN PROGRESS', 'HELD'])::text as status
    )
    SELECT status FROM w_pending_sale_status;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions