You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
Improve wrong-tuple-type error reports in contrib/tablefunc.
These messages were fairly confusing, and didn't match thecolumn names used in the SGML docs. Try to improve that.Also use error codes more specific than ERRCODE_SYNTAX_ERROR.Patch by me, reviewed by Joe ConwayDiscussion:https://postgr.es/m/18937.1709676295@sss.pgh.pa.us
Copy file name to clipboardExpand all lines: contrib/tablefunc/expected/tablefunc.out
+77-8Lines changed: 77 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -145,6 +145,23 @@ SELECT * FROM crosstab_out('SELECT rowid, attribute, val FROM ct where rowclass
145
145
| val9 | val10 | val11
146
146
(3 rows)
147
147
148
+
-- check error reporting
149
+
SELECT * FROM crosstab('SELECT rowid, val FROM ct where rowclass = ''group1'' and (attribute = ''att2'' or attribute = ''att3'') ORDER BY 1,2;')
150
+
AS ct(row_name text, category_1 text, category_2 text);
151
+
ERROR: invalid crosstab source data query
152
+
DETAIL: The query must return 3 columns: row_name, category, and value.
153
+
SELECT * FROM crosstab('SELECT rowid, attribute, val FROM ct where rowclass = ''group1'' and (attribute = ''att2'' or attribute = ''att3'') ORDER BY 1,2;')
154
+
AS ct(row_name text);
155
+
ERROR: invalid crosstab return type
156
+
DETAIL: Return row must have at least two columns.
157
+
SELECT * FROM crosstab('SELECT rowid, attribute, val FROM ct where rowclass = ''group1'' and (attribute = ''att2'' or attribute = ''att3'') ORDER BY 1,2;')
158
+
AS ct(row_name int, category_1 text, category_2 text);
159
+
ERROR: invalid crosstab return type
160
+
DETAIL: Source row_name datatype text does not match return row_name datatype integer.
161
+
SELECT * FROM crosstab('SELECT rowid, attribute, val FROM ct where rowclass = ''group1'' and (attribute = ''att2'' or attribute = ''att3'') ORDER BY 1,2;')
162
+
AS ct(row_name text, category_1 text, category_2 int);
163
+
ERROR: invalid crosstab return type
164
+
DETAIL: Source value datatype text does not match return value datatype integer in column 3.
148
165
--
149
166
-- hash based crosstab
150
167
--
@@ -216,13 +233,20 @@ SELECT * FROM crosstab(
216
233
'SELECT rowid, rowdt, attribute, val FROM cth ORDER BY 1',
217
234
'SELECT DISTINCT attribute FROM cth WHERE attribute = ''a'' ORDER BY 1')
218
235
AS c(rowid text, rowdt timestamp, temperature int4, test_result text, test_startdate timestamp, volts float8);
219
-
ERROR:provided "categories" SQL must return 1 column of at least one row
236
+
ERROR:crosstabcategories query must return at least one row
220
237
-- if category query generates more than one column, get expected error
221
238
SELECT * FROM crosstab(
222
239
'SELECT rowid, rowdt, attribute, val FROM cth ORDER BY 1',
223
240
'SELECT DISTINCT rowdt, attribute FROM cth ORDER BY 2')
224
241
AS c(rowid text, rowdt timestamp, temperature int4, test_result text, test_startdate timestamp, volts float8);
225
-
ERROR: provided "categories" SQL must return 1 column of at least one row
242
+
ERROR: invalid crosstab categories query
243
+
DETAIL: The query must return one column.
244
+
-- if category query generates a NULL value, get expected error
245
+
SELECT * FROM crosstab(
246
+
'SELECT rowid, rowdt, attribute, val FROM cth ORDER BY 1',
247
+
'SELECT NULL::text')
248
+
AS c(rowid text, rowdt timestamp, temperature int4, test_result text, test_startdate timestamp, volts float8);
249
+
ERROR: crosstab category value must not be null
226
250
-- if source query returns zero rows, get zero rows returned
227
251
SELECT * FROM crosstab(
228
252
'SELECT rowid, rowdt, attribute, val FROM cth WHERE false ORDER BY 1',
@@ -241,6 +265,26 @@ AS c(rowid text, rowdt timestamp, temperature text, test_result text, test_start