Re: SQL functions, INSERT/UPDATE/DELETE RETURNING, and triggers

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: SQL functions, INSERT/UPDATE/DELETE RETURNING, and triggers
Date: 2006-10-12 22:07:49
Message-ID: 19990.1160690869@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 is
specified 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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jeff Davis 2006-10-12 22:15:03 Re: Hints proposal
Previous Message Bruce Momjian 2006-10-12 22:03:38 Re: New version of money type