Re: BUG #16176: NULL value returned by category_sql argument to crosstab() causes segmentation fault

Joe Conway <mail@joeconway.com>

From: Joe Conway <mail@joeconway.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: ipluta@wp.pl, pgsql-bugs@lists.postgresql.org
Date: 2019-12-23T19:00:38Z
Lists: pgsql-bugs
On 12/23/19 1:49 PM, Tom Lane wrote:
> Joe Conway <mail@joeconway.com> writes:
>> Pushed that way to all supported branches.
> 
> Hmm, why'd you use ERRCODE_SYNTAX_ERROR, and not say
> ERRCODE_NULL_VALUE_NOT_ALLOWED?

To be consistent with the error just above:
--------------------
/*
 * The provided categories SQL query must always return one column:
 * category - the label or identifier for each column
 */
if (spi_tupdesc->natts != 1)
	ereport(ERROR,
	(errcode(ERRCODE_SYNTAX_ERROR),
	 errmsg("provided \"categories\" SQL must " \
	"return 1 column of at least one row")));
--------------------

Also, the argument itself is a SQL statement, and it isn't NULL, it just
produces a NULL value as one (or more) of its output rows. It seems like
ERRCODE_NULL_VALUE_NOT_ALLOWED might be confusing.

But I am not married to ERRCODE_SYNTAX_ERROR if you think it ought to be
changed.

Joe
-- 
Crunchy Data - http://crunchydata.com
PostgreSQL Support for Secure Enterprises
Consulting, Training, & Open Source Development

Commits

  1. Disallow null category in crosstab_hash