Re: Adding OLD/NEW support to RETURNING

jian he <jian.universality@gmail.com>

From: jian he <jian.universality@gmail.com>
To: Dean Rasheed <dean.a.rasheed@gmail.com>
Cc: Robert Treat <rob@xzilla.net>, Jeff Davis <pgsql@j-davis.com>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>, Tomas Vondra <tomas@vondra.me>
Date: 2025-01-08T06:16:38Z
Lists: pgsql-hackers
hi.
two minor issues.

    if (qry->returningList == NIL)
        ereport(ERROR,
                (errcode(ERRCODE_SYNTAX_ERROR),
                 errmsg("RETURNING must have at least one column"),
                 parser_errposition(pstate,

exprLocation(linitial(returningClause->exprs)))));

we can reduce one level parenthesis by:
    if (qry->returningList == NIL)
        ereport(ERROR,
                (errcode(ERRCODE_SYNTAX_ERROR),
                 errmsg("RETURNING must have at least one column"),
                 parser_errposition(pstate,

exprLocation(linitial(returningClause->exprs))));

seems no tests for this error case.
we can add one in case someone in future is wondering if this is ever reachable.
like:
create temp table s1();
insert into s1 default values returning new.*;
drop temp table s1;


transformReturningClause
case RETURNING_OPTION_NEW: not tested,
we can add one at src/test/regress/sql/returning.sql line 176:

INSERT INTO foo DEFAULT VALUES RETURNING WITH (new AS n, old AS o, new as n) *;



Commits

  1. doc: Updates for RETURNING OLD/NEW.

  2. Fix parsing of qualified relation names in RETURNING.

  3. Add OLD/NEW support to RETURNING in DML queries.

  4. Remove useless casts to (void *)

  5. Refactor/reword some error messages to avoid duplicates