aboutsummaryrefslogtreecommitdiff
path: root/contrib/tablefunc/tablefunc.c
diff options
context:
space:
mode:
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 */