| From: | Joao Rito <joaovictor(dot)rito(at)gmail(dot)com> |
|---|---|
| To: | Tender Wang <tndrwang(at)gmail(dot)com> |
| Cc: | pgsql-bugs(at)lists(dot)postgresql(dot)org |
| Subject: | Re: BUG #19689: MERGE INSERT accepts a set-returning function during PREPARE but fails at EXECUTE |
| Date: | 2026-11-19 12:26:49 |
| Message-ID: | 20261119122649.39979-1-joaovictor.rito@gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-bugs |
Hi Tender,
Thank you for the patch. I tried to review it. I may be wrong on some points, so please correct me.
What I did:
- Built current master (19ab0ba) with --enable-cassert, and reproduced the report. PREPARE succeeds and EXECUTE fails with "set-valued function called in context that cannot accept a set".
- Applied the patch (it applied cleanly) and rebuilt. PREPARE and direct MERGE now fail at parse time with "set-returning functions are not allowed in MERGE INSERT actions", and the error position points at the function call.
- Checked SRFs nested in an expression (`generate_series(1,2) + 1`), in a multi-column INSERT, and `unnest(...)`. All are rejected the same way.
- Checked that other cases did not change: SRF in WHEN MATCHED UPDATE and in WHEN NOT MATCHED BY SOURCE UPDATE (already rejected with the UPDATE message), SRF in the WHEN condition, in ON, and in RETURNING (same errors as before). An SRF in the USING subquery and an SRF inside a scalar sub-SELECT in INSERT VALUES still work as before. Plain INSERT with an SRF still works.
- Ran `make check`: all 243 tests passed.
Some small thoughts, which you may know better than me:
1. The patch has no regression test yet. I think a test in src/test/regress/sql/merge.sql with the PREPARE case from the report would be useful.
2. The error text is "set-returning functions are not allowed in MERGE INSERT actions". Other messages use the form "... not allowed in UPDATE", "... not allowed in MERGE WHEN conditions". Maybe a name from the existing ParseExprKindName() style would be more consistent, but I am not sure.
3. I did not check the back branches, so I do not know whether a backpatch is wanted.
I think the direction looks right to me, because I could not find a valid MERGE that reaches the executor error.
What I did not test:
- Back branches (17, 18). Only master was tested.
- Other build setups (no assertions, Windows, meson), and other test suites (`make check-world`, isolation, TAP).
- MERGE on partitioned tables, views, and inherited tables.
- MERGE inside PL/pgSQL or a SQL function body, and with parameters ($1) instead of constants.
- Other ways to produce a set in INSERT VALUES (ROWS FROM, SRF returning composite types, SRF with `OVERRIDING`).
- Documentation wording. I did not check the docs for any note about SRFs in MERGE.
- Code style (pgindent) and the placement of the new `#include`.
Thanks again for the patch,
Joao Rito
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Daniel Gustafsson | 2026-11-19 12:26:56 | Re: BUG #19920: Out-of-Bounds Read on a Zero-Length Array in pg_trgm word_similarity('', '') |
| Previous Message | Rajesh Kumar Thandapani | 2026-11-19 12:16:15 | Re: BUG #19776: pg_combinebackup ignores the truncation_block_length of an intermediate incremental backup |