Re: SQL functions, INSERT/UPDATE/DELETE RETURNING, and triggers - Mailing list pgsql-hackers

From Tom Lane
Subject Re: SQL functions, INSERT/UPDATE/DELETE RETURNING, and triggers
Date
Msg-id 19990.1160690869@sss.pgh.pa.us
Whole thread Raw
In response to SQL functions, INSERT/UPDATE/DELETE RETURNING, and triggers  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: SQL functions, INSERT/UPDATE/DELETE RETURNING,  (Bruce Momjian <bruce@momjian.us>)
List pgsql-hackers
I wrote:
> ISTM that ideally, a query with RETURNING ought to act like a SELECT
> for the purposes of a SQL function --- to wit, that the result rows are
> discarded if it's not the last query in the function, and are returned
> as the function result if it is.

The current state of affairs is that the first part of that works as
expected, and the second part fails like so:

regression=# create function foo8(bigint,bigint) returns setof int8_tbl as
$$ insert into int8_tbl values($1,$2) returning * $$
language sql;
ERROR:  return type mismatch in function declared to return int8_tbl
DETAIL:  Function's final statement must be a SELECT.
CONTEXT:  SQL function "foo8"
regression=#

While this is certainly undesirable, it looks more like a missing
feature than a bug, especially since the documentation says exactly
that:
... the final command must be a SELECT that returns whatever isspecified as the function's return type.

I spent some time looking at what it would take to fix it, and I find
that the changes are a bit bigger than I want to be making in mid-beta.
So my recommendation is that for now we just add a TODO item:

* Allow SQL-language functions to return results from RETURNING queries
        regards, tom lane


pgsql-hackers by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: New version of money type
Next
From: Jeff Davis
Date:
Subject: Re: [PERFORM] Hints proposal