| From: | Sho Ito <i(dot)sho(dot)0628(at)gmail(dot)com> |
|---|---|
| To: | pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | [PATCH v1] Preserve implicit composite casts in ROW deparsing |
| Date: | 2026-11-16 04:26:37 |
| Message-ID: | CAG7L5+5Y1djbWgrscKq_Hd+xrQUuVRM0eyajLUa7243DJss72w@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi hackers,
An implicitly coerced composite argument can lose its type when a stored
expression is deparsed. After another function overload is added,
recreating a view can fail with an ambiguous-function error or silently
call a different function.
For example, in a fresh database:
```sql
CREATE TYPE pair AS (a int, b int);
CREATE FUNCTION pick(pair) RETURNS int
LANGUAGE sql AS 'SELECT 1';
CREATE VIEW v AS SELECT pick(ROW(1, 2)) AS r;
CREATE FUNCTION pick(record) RETURNS int
LANGUAGE plpgsql AS 'BEGIN RETURN 2; END';
SELECT r FROM v; -- 1
SELECT 'CREATE VIEW v_copy AS ' || pg_get_viewdef('v') \gexec
SELECT r FROM v_copy; -- 2 before the fix, 1 after
```
The stored call correctly refers to `pick(pair)`, but `pg_get_viewdef()`
prints `pick(ROW(1, 2))` without `::pair`. On reparse, the `record`
overload wins.
`get_func_expr()` requests `showimplicit = true` for its arguments, but
the `RowExpr` printer did not honour that flag for implicitly coerced
named composites. The attached v1 prints the named composite type when
`showimplicit` is true, leaving anonymous `record` output unchanged.
The patch also updates existing `EXPLAIN` expectations that now show
named-type casts.
I think this merits backpatching because it can silently change results
after restore. I have only tested master so far, but I'm happy to help
prepare and test back-branch versions if appropriate.
Regards,
Sho
--
=======================================
*Sho Ito (Sean)*
E-mail: i(dot)sho(dot)0628(at)gmail(dot)com
LinkedIn: *https://www.linkedin.com/in/sho-ito-0628/
<https://www.linkedin.com/in/sho-ito-0628/>*
GitHub: https://github.com/sean0628/
=======================================
| Attachment | Content-Type | Size |
|---|---|---|
| v1-0001-Preserve-implicit-composite-casts-in-ROW-deparse.patch | application/octet-stream | 11.8 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Amit Kapila | 2026-11-16 04:34:52 | Re: Assertion failure in update_local_synced_slot(), slotsync.c:364 |
| Previous Message | Zhijie Hou | 2026-11-16 04:20:31 | Re: Assertion failure in update_local_synced_slot(), slotsync.c:364 |