Skip to content

duckdb: columns produced by unnest(..., recursive := true) do not resolve #4713

Backlog

Description

@kyleconroy

Version

main at commit 3ad8b20 (2026-10-23). sqlc version prints v1.31.1.

What happened?

In DuckDB, unnest(items, recursive := true) on a list of structs expands into one column per struct field (type, amount). sqlc treats it as a single column:

  • In a top-level select, the result is one column named Unnest, typed any.
  • In a CTE, selecting the expanded fields by name fails with unknown column "type".

Expected: one column per struct field, each with the field's name and type.

Workaround: unnest without recursive, then read each field with CAST(struct_extract(it, 'type') AS VARCHAR) (see #4714 and #4655).

Relevant log output

# query 1 generates:
type ListItemsRow struct {
	ID     string
	Unnest any
}

# query 2:
# package db
query.sql:1:1: unknown column "type"

Database schema

CREATE TABLE transactions (id VARCHAR NOT NULL, items STRUCT(type VARCHAR, amount INTEGER)[]);

SQL queries

-- query 1
-- name: ListItems :many
SELECT id, unnest(items, recursive := true) FROM transactions;

-- query 2
-- name: ListItems :many
WITH i AS (SELECT id, unnest(items, recursive := true) FROM transactions)
SELECT id, type, amount FROM i;

Configuration

version: "2"
sql:
  - engine: duckdb
    schema: schema.sql
    queries: query.sql
    gen:
      go:
        package: db
        out: db

What operating system are you using?

Linux

What database engines are you using?

DuckDB

What type of code are you generating?

Go


Generated by Claude Code

Activity

  1. added
    bug
    on Nov 30, 2026
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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions