Skip to content

fix: Refresh the column types of empty results from prepared queries - #676

Merged
krlmlr merged 5 commits into
mainfrom
claude/pg-duckdb-zero-rows
Nov 29, 2026
Merged

krlmlr merged 5 commits into
mainfrom
claude/pg-duckdb-zero-rows

Conversation

@krlmlr

@krlmlr krlmlr commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #539 (merged), for #526; decided in #674 (comment).

With pg_duckdb, the prepare step reports a placeholder shape for some queries. #539 stops enforcing that shape once rows arrive, but a result without rows returned in step_run() before the column cache was refreshed, so it kept the placeholder: SELECT * FROM read_csv(...) LIMIT 0 returned a single read_csv column instead of id and name.

This PR refreshes the cache from a PGRES_TUPLES_OK result too, for prepared queries only. Immediate queries are left as they were, because a multi-statement query such as SELECT 1 AS a WHERE false; SELECT 'x' AS b would otherwise error instead of returning column b.

No tests added, as requested on #674. Checked locally: the package builds, the full test suite passes against PostgreSQL 16 (0 failures, 9341 passed, 10 skipped), the multi-statement query above still returns column b, and against pgduckdb/pgduckdb:17-v1.0.0 the LIMIT 0 query now returns id and name (with #539 alone: read_csv).

Clean review: nothing above Low; Accepted limitations.

https://claude.ai/code/session_01Hr1rd6e5NcxC9GSrNJDokc


Generated by Claude Code

toppyy and others added 5 commits December 20, 2025 21:26
A result without rows returned before the column cache was refreshed,
so it kept the shape reported by the prepare step.
With pg_duckdb, that shape is a placeholder,
and `SELECT * FROM read_csv(...) LIMIT 0` returned one `read_csv` column.
Immediate queries keep the old behavior,
since their statements may return different columns.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd6e5NcxC9GSrNJDokc

krlmlr commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

Accepted limitations

The clean review (one round) found nothing above Low. On plain PostgreSQL, output is byte-identical to #539 alone: zero-row prepared queries for int8, text, timestamptz, json, numeric and bytea; dbColumnInfo(), dbFetch() and rebinding on empty results; multi-row dbBind() mixing zero-row and data rows; immediate multi-statement queries.

  • src/PqResultImpl.cpp#L483: with several parameter rows, an empty group's columns are now checked against the cache. If pg_duckdb described an empty result differently from a data result, multi-row dbBind() would fail with "Multiple queries must use the same column types". Untested without pg_duckdb. Relevance: low. Confidence: low.
  • No regression test and no NEWS entry, as Kirill asked ("No testing needed"). A test mixing zero-row and data rows in a multi-row dbBind(), plus the immediate multi-statement case, would lock in the !immediate_ restriction without pg_duckdb. Relevance: low. Confidence: high.

Generated by Claude Code

@krlmlr
krlmlr merged commit d244162 into main Nov 29, 2026
9 checks passed
@krlmlr
krlmlr deleted the claude/pg-duckdb-zero-rows branch November 29, 2026 20:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants