aboutsummaryrefslogtreecommitdiff
path: root/contrib/tablefunc/tablefunc.c
diff options
context:
space:
mode:
authorJoe Conway <mail@joeconway.com>2004-08-11 00:49:35 +0000
committerJoe Conway <mail@joeconway.com>2004-08-11 00:49:35 +0000
commitbc8a1fc282005f6da9ff7650eadc65b160077e43 (patch)
treeaa557e7317735b2b9385c30d7fe8b5ae68e75730 /contrib/tablefunc/tablefunc.c
parent7d3b7db8da4132459e92a869833fe481be2ebca2 (diff)
downloadpostgresql-bc8a1fc282005f6da9ff7650eadc65b160077e43.tar.gz
postgresql-bc8a1fc282005f6da9ff7650eadc65b160077e43.zip
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.
Diffstat (limited to 'contrib/tablefunc/tablefunc.c')
-rw-r--r--contrib/tablefunc/tablefunc.c23
1 files changed, 9 insertions, 14 deletions
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 */