Repository navigation
Conversation
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd6e5NcxC9GSrNJDokc
Resolved: How should #539 land?#539 fixes #526 with a 5-line change that is inert for plain PostgreSQL (full suite unchanged on
Generated by Claude Code |
Question: What test covers #526?Plain PostgreSQL cannot make a prepared query's execution differ from its description: the server refuses with "cached plan must not change result type", so the "pedestrian" test asked about on #539 does not exist (reprex in the PR body). A test needs pg_duckdb, for example
Generated by Claude Code |
Resolved: Also fix zero-row results from pg_duckdb?With and without #539, a pg_duckdb query that returns no rows keeps the placeholder shape from the prepare step:
Kirill decided: separate PR, stacked on top of #539 (#674 (comment): "Stacked PR on top for the zero-rows fix. No testing needed. I'll merge myself."). Generated by Claude Code |
|
Stacked PR on top for the zero-rows fix. No testing needed. I'll merge myself. |
|
Prepare the PR now, open after I merge. |
|
PR merged. |
|
Opened the zero-row fix as #676 on top of the merged #539 (6 lines in Generated by Claude Code |
Review of #526 (
Multiple queries must use the same column names.with pg_duckdb) and its proposed fix #539 ("Do not enforce types when preparing query"), as asked. This PR changes no code; it only records the findings and the open decisions. Nothing was posted on #526 or #539.Summary
main(1.4.10.9021 at 7285d13) and on CRAN 1.4.10, identically, againstpgduckdb/pgduckdb:17-v1.0.0in Docker, including the exact S3 query from the issue.main, every query from the reprex returns the expected data, including parametrized queries anddbBind()with several parameter rows.NOT_CRAN=true, PostgreSQL 16: 9351 passed, 0 failed, 10 skipped, same asmain).Cause
RPostgres prepares every non-immediate query, reads its result shape with
PQdescribePrepared(), and fixes the column cache from that description (_cache::set()setsinitialized_ = true). Every later result is compared against it. pg_duckdb describes queries over DuckDB table functions with placeholder columns and resolves the real ones only at execution:SELECT * FROM read_csv(...)describes as one columnread_csvof typeduckdb.row(hence the "column names" error), andSELECT r['id'] AS id ...asidof typeduckdb.unresolved_type(hence a "column types" error). The comparison exists for multi-statement immediate queries, which a prepared statement can never be.Reprex on
mainCRAN 1.4.10 gives the same output, except for the version and one extra "Closing open result set" warning.
Same reprex with #539 merged onto
mainEdge cases with #539 (zero rows, a first parameter row without matches, rebinding):
On
main, the last two cases fail with "Multiple queries must use the same column types."Evaluation of #539
_cache::set()gets anenforce_resultflag; the prepare step passesfalse, so the description fills the cache without fixing it, and the first execution result passestrue, so the server's real shape becomes the reference for all later parameter rows and rebinds. 5 lines in two files; it applies tomaincleanly (its head 10dcae2 already containsmain).dbBind()with changing types: RPostgres uses the unnamed statement only; parameter types come from the prepare step and are not touched by feat: Do not enforce types when preparing query for compatibility with pg_duckdb #539. Rebinding a result and binding several parameter rows still compare later results against the first one (see edge cases above).dbColumnInfo()on an unbound parametrized result), the placeholder description still shows. That is what the server reports and cannot be improved without executing.PGRES_TUPLES_OKand returns before the cache is refreshed, soSELECT * FROM read_csv(...) LIMIT 0gives oneread_csvcolumn instead ofidandname. Refreshing the cache from that result too fixes this (tried in a scratch build: zero rows then giveidandname, full suite still green), but for immediate multi-statement queries it adds a new error when an earlier statement returns no rows:On
mainand with #539, the first of these returns columnb. Restricting the refresh to prepared queries avoids that. This is a separate, smaller issue and not needed for #526.So a test needs pg_duckdb (or another extension that resolves result types at execution). CI uses
ankane/setup-postgreswithout extensions.immediate = TRUEalready works around "! Multiple queries must use the same column names." when issuing a query against a Postgres server running with the pg_duckdb extension #526 without any change (shown in the reprex), but users hit the error first and cannot guess the workaround. Dropping the prepare-time cache entirely would breakdbColumnInfo()anddbGetRowsAffected()before binding. feat: Do not enforce types when preparing query for compatibility with pg_duckdb #539 is already the targeted minimal change.Recommendation
Merge #539's approach with a regression test that skips unless the server has pg_duckdb, run by one Linux CI job against the
pgduckdb/pgduckdbimage, plus a NEWS bullet. Treat zero-row results as a follow-up. The decisions are in the question comments below.Related: #526, #539.
Generated by Claude Code