I just realized that there's a problem with the patch I applied here
http://archives.postgresql.org/pgsql-committers/2007-03/msg00057.php
to ensure that the result type of an inline'd SQL function is correctly
marked in the resulting expression tree.  To wit, it doesn't work for
functions returning pseudotypes:

regression=# create function if(bool,anyelement,anyelement) returns anyelement
regression-# as $$ select case when $1 then $2 else $3 end $$ language sql;
CREATE FUNCTION
regression=# explain verbose select if(true,1,2) from int4_tbl;
server closed the connection unexpectedly

The crash is because this newly-added assert fails:

        Assert(IsBinaryCoercible(exprType(newexpr), funcform->prorettype));

and beyond that, we don't actually want the other added line (adding a
RelabelType node) either, because it'd be relabeling the expression as
type ANYELEMENT which is entirely unhelpful.

I think the correct thing is to do nothing, and assume the expanded
expression must have the right type already, if the function is declared
to return a pseudotype.  The only pseudotypes allowed as SQL-function
results are RECORD, VOID, and polymorphic, and this seems OK and maybe
even required in each case.  But having gotten this wrong once already,
maybe I better call for comments...

                        regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Reply via email to