Another problem with result type selection in inline_function

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Joe Conway <mail(at)joeconway(dot)com>
Cc: pgsql-hackers(at)postgreSQL(dot)org
Subject: Another problem with result type selection in inline_function
Date: 2007-05-01 15:33:17
Message-ID: 17607.1178033597@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2007-05-01 15:37:42 Re: Heap page diagnostic functions
Previous Message Dave Page 2007-05-01 15:26:03 Re: Feature freeze progress report