Re: segmentation fault in pg head with SQL function. - Mailing list pgsql-hackers

From Tom Lane
Subject Re: segmentation fault in pg head with SQL function.
Date
Msg-id 27775.1521214821@sss.pgh.pa.us
Whole thread Raw
In response to Re: segmentation fault in pg head with SQL function.  (Michael Paquier <michael@paquier.xyz>)
Responses Re: segmentation fault in pg head with SQL function.  (Peter Eisentraut <peter.eisentraut@2ndquadrant.com>)
List pgsql-hackers
Michael Paquier <michael@paquier.xyz> writes:
> On Fri, Mar 16, 2018 at 11:35:13AM +0530, Prabhat Sahu wrote:
>> postgres=# CREATE OR REPLACE FUNCTION func1() RETURNS VOID
>> LANGUAGE SQL
>> AS $$
>> select 10;
>> $$;

> Problem reproducible here, and the bug has been introduced by fd1a421f.
> It seems to me that the function should not be authorized to be created
> to begin with, as it returns an integer in its last query, where I think
> that check_sql_fn_retval is doing it wrong when called in
> inline_function() as we know that it handles a function, and not a
> procedure thanks to the first sanity checks at the top of the function.

Hm.  Actually, I think this is my fault.  It is true that previous PG
versions would have rejected this function definition, but my intention
while revising Peter's prokind patch was that we'd start allowing a
VOID-returning SQL function to contain anything, and just ignore whatever
the last statement within it might be.  The documentation doesn't say
much about VOID-returning SQL functions, but I certainly don't see
anything saying that they can't end with a SELECT, so arguably the old
behavior is a POLA violation.  In any case, this is the behavior we
need for VOID-returning procedures, and there seems little reason not
to make functions act similarly.

So apparently I missed something with that.  Will look more closely.

            regards, tom lane


pgsql-hackers by date:

Previous
From: Tomas Vondra
Date:
Subject: Re: MCV lists for highly skewed distributions
Next
From: Aleksander Alekseev
Date:
Subject: Re: GSOC :Thrift datatype support (2018)