@@ -127,7 +127,7 @@ SELECT * FROM crosstab('SELECT rowid, attribute, val FROM ct where rowclass = ''
127127-- hash based crosstab
128128--
129129create table cth(id serial, rowid text, rowdt timestamp, attribute text, val text);
130- NOTICE: CREATE TABLE will create implicit sequence "cth_id_seq" for " serial" column "cth.id"
130+ NOTICE: CREATE TABLE will create implicit sequence "cth_id_seq" for serial column "cth.id"
131131insert into cth values(DEFAULT,'test1','01 March 2003','temperature','42');
132132insert into cth values(DEFAULT,'test1','01 March 2003','test_result','PASS');
133133-- the next line is intentionally left commented and is therefore a "missing" attribute
@@ -193,6 +193,24 @@ SELECT * FROM crosstab(
193193 'SELECT DISTINCT rowdt, attribute FROM cth ORDER BY 2')
194194AS c(rowid text, rowdt timestamp, temperature int4, test_result text, test_startdate timestamp, volts float8);
195195ERROR: provided "categories" SQL must return 1 column of at least one row
196+ -- if source query returns zero rows, get zero rows returned
197+ SELECT * FROM crosstab(
198+ 'SELECT rowid, rowdt, attribute, val FROM cth WHERE false ORDER BY 1',
199+ 'SELECT DISTINCT attribute FROM cth ORDER BY 1')
200+ AS c(rowid text, rowdt timestamp, temperature text, test_result text, test_startdate text, volts text);
201+ rowid | rowdt | temperature | test_result | test_startdate | volts
202+ -------+-------+-------------+-------------+----------------+-------
203+ (0 rows)
204+
205+ -- if source query returns zero rows, get zero rows returned even if category query generates no rows
206+ SELECT * FROM crosstab(
207+ 'SELECT rowid, rowdt, attribute, val FROM cth WHERE false ORDER BY 1',
208+ 'SELECT DISTINCT attribute FROM cth WHERE false ORDER BY 1')
209+ AS c(rowid text, rowdt timestamp, temperature text, test_result text, test_startdate text, volts text);
210+ rowid | rowdt | temperature | test_result | test_startdate | volts
211+ -------+-------+-------------+-------------+----------------+-------
212+ (0 rows)
213+
196214--
197215-- connectby
198216--
0 commit comments