From bc8a1fc282005f6da9ff7650eadc65b160077e43 Mon Sep 17 00:00:00 2001 From: Joe Conway Date: Wed, 11 Aug 2004 00:49:35 +0000 Subject: Hashed crosstab was dying with an SPI_finish error when the source SQL produced no rows. Now it returns 0 rows instead. Adjusted regression test for this case. --- contrib/tablefunc/tablefunc.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) (limited to 'contrib/tablefunc/tablefunc.c') diff --git a/contrib/tablefunc/tablefunc.c b/contrib/tablefunc/tablefunc.c index 3eccebf476f..f14c3963026 100644 --- a/contrib/tablefunc/tablefunc.c +++ b/contrib/tablefunc/tablefunc.c @@ -821,15 +821,6 @@ load_categories_hash(char *cats_sql, MemoryContext per_query_ctx) MemoryContextSwitchTo(SPIcontext); } } - else - { - /* no qualifying tuples */ - SPI_finish(); - ereport(ERROR, - (errcode(ERRCODE_SYNTAX_ERROR), - errmsg("provided \"categories\" SQL must " \ - "return 1 column of at least one row"))); - } if (SPI_finish() != SPI_OK_FINISH) /* internal error */ @@ -879,6 +870,15 @@ get_crosstab_tuplestore(char *sql, j; int result_ncols; + if (num_categories == 0) + { + /* no qualifying category tuples */ + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("provided \"categories\" SQL must " \ + "return 1 column of at least one row"))); + } + /* * The provided SQL query must always return at least three * columns: @@ -994,11 +994,6 @@ get_crosstab_tuplestore(char *sql, MemoryContextSwitchTo(SPIcontext); } - else - { - /* no qualifying tuples */ - SPI_finish(); - } if (SPI_finish() != SPI_OK_FINISH) /* internal error */ -- cgit v1.2.3