mirror of
https://github.com/postgres/postgres.git
synced 2025-07-30 11:03:19 +03:00
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.
This commit is contained in:
@ -193,6 +193,24 @@ SELECT * FROM crosstab(
|
|||||||
'SELECT DISTINCT rowdt, attribute FROM cth ORDER BY 2')
|
'SELECT DISTINCT rowdt, attribute FROM cth ORDER BY 2')
|
||||||
AS c(rowid text, rowdt timestamp, temperature int4, test_result text, test_startdate timestamp, volts float8);
|
AS c(rowid text, rowdt timestamp, temperature int4, test_result text, test_startdate timestamp, volts float8);
|
||||||
ERROR: provided "categories" SQL must return 1 column of at least one row
|
ERROR: provided "categories" SQL must return 1 column of at least one row
|
||||||
|
-- if source query returns zero rows, get zero rows returned
|
||||||
|
SELECT * FROM crosstab(
|
||||||
|
'SELECT rowid, rowdt, attribute, val FROM cth WHERE false ORDER BY 1',
|
||||||
|
'SELECT DISTINCT attribute FROM cth ORDER BY 1')
|
||||||
|
AS c(rowid text, rowdt timestamp, temperature text, test_result text, test_startdate text, volts text);
|
||||||
|
rowid | rowdt | temperature | test_result | test_startdate | volts
|
||||||
|
-------+-------+-------------+-------------+----------------+-------
|
||||||
|
(0 rows)
|
||||||
|
|
||||||
|
-- if source query returns zero rows, get zero rows returned even if category query generates no rows
|
||||||
|
SELECT * FROM crosstab(
|
||||||
|
'SELECT rowid, rowdt, attribute, val FROM cth WHERE false ORDER BY 1',
|
||||||
|
'SELECT DISTINCT attribute FROM cth WHERE false ORDER BY 1')
|
||||||
|
AS c(rowid text, rowdt timestamp, temperature text, test_result text, test_startdate text, volts text);
|
||||||
|
rowid | rowdt | temperature | test_result | test_startdate | volts
|
||||||
|
-------+-------+-------------+-------------+----------------+-------
|
||||||
|
(0 rows)
|
||||||
|
|
||||||
--
|
--
|
||||||
-- connectby
|
-- connectby
|
||||||
--
|
--
|
||||||
|
@ -88,6 +88,17 @@ SELECT * FROM crosstab(
|
|||||||
'SELECT DISTINCT rowdt, attribute FROM cth ORDER BY 2')
|
'SELECT DISTINCT rowdt, attribute FROM cth ORDER BY 2')
|
||||||
AS c(rowid text, rowdt timestamp, temperature int4, test_result text, test_startdate timestamp, volts float8);
|
AS c(rowid text, rowdt timestamp, temperature int4, test_result text, test_startdate timestamp, volts float8);
|
||||||
|
|
||||||
|
-- if source query returns zero rows, get zero rows returned
|
||||||
|
SELECT * FROM crosstab(
|
||||||
|
'SELECT rowid, rowdt, attribute, val FROM cth WHERE false ORDER BY 1',
|
||||||
|
'SELECT DISTINCT attribute FROM cth ORDER BY 1')
|
||||||
|
AS c(rowid text, rowdt timestamp, temperature text, test_result text, test_startdate text, volts text);
|
||||||
|
|
||||||
|
-- if source query returns zero rows, get zero rows returned even if category query generates no rows
|
||||||
|
SELECT * FROM crosstab(
|
||||||
|
'SELECT rowid, rowdt, attribute, val FROM cth WHERE false ORDER BY 1',
|
||||||
|
'SELECT DISTINCT attribute FROM cth WHERE false ORDER BY 1')
|
||||||
|
AS c(rowid text, rowdt timestamp, temperature text, test_result text, test_startdate text, volts text);
|
||||||
|
|
||||||
--
|
--
|
||||||
-- connectby
|
-- connectby
|
||||||
|
@ -831,15 +831,6 @@ load_categories_hash(char *cats_sql, MemoryContext per_query_ctx)
|
|||||||
MemoryContextSwitchTo(SPIcontext);
|
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)
|
if (SPI_finish() != SPI_OK_FINISH)
|
||||||
/* internal error */
|
/* internal error */
|
||||||
@ -889,6 +880,15 @@ get_crosstab_tuplestore(char *sql,
|
|||||||
j;
|
j;
|
||||||
int result_ncols;
|
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
|
* The provided SQL query must always return at least three
|
||||||
* columns:
|
* columns:
|
||||||
@ -1004,11 +1004,6 @@ get_crosstab_tuplestore(char *sql,
|
|||||||
MemoryContextSwitchTo(SPIcontext);
|
MemoryContextSwitchTo(SPIcontext);
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
/* no qualifying tuples */
|
|
||||||
SPI_finish();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (SPI_finish() != SPI_OK_FINISH)
|
if (SPI_finish() != SPI_OK_FINISH)
|
||||||
/* internal error */
|
/* internal error */
|
||||||
|
Reference in New Issue
Block a user