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: [email protected]
LinkedIn: *https://www.linkedin.com/in/sho-ito-0628/
<https://www.linkedin.com/in/sho-ito-0628/>*
GitHub: https://github.com/sean0628/
=======================================

Attachment: v1-0001-Preserve-implicit-composite-casts-in-ROW-deparse.patch
Description: Binary data

Reply via email to