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
CREATETABLEct(id int, rowclass text, rowidtext, attribute text, val text);
14
+
CREATETABLEct(id int, rowclass text, orarowidtext, attribute text, val text);
15
15
\copy ct from'data/ct.data'
16
16
17
-
SELECT*FROM crosstab2('SELECT rowid, attribute, val FROM ct where rowclass = ''group1'' and (attribute = ''att2'' or attribute = ''att3'') ORDER BY 1,2;');
18
-
SELECT*FROM crosstab3('SELECT rowid, attribute, val FROM ct where rowclass = ''group1'' and (attribute = ''att2'' or attribute = ''att3'') ORDER BY 1,2;');
19
-
SELECT*FROM crosstab4('SELECT rowid, attribute, val FROM ct where rowclass = ''group1'' and (attribute = ''att2'' or attribute = ''att3'') ORDER BY 1,2;');
17
+
SELECT*FROM crosstab2('SELECT orarowid, attribute, val FROM ct where rowclass = ''group1'' and (attribute = ''att2'' or attribute = ''att3'') ORDER BY 1,2;');
18
+
SELECT*FROM crosstab3('SELECT orarowid, attribute, val FROM ct where rowclass = ''group1'' and (attribute = ''att2'' or attribute = ''att3'') ORDER BY 1,2;');
19
+
SELECT*FROM crosstab4('SELECT orarowid, attribute, val FROM ct where rowclass = ''group1'' and (attribute = ''att2'' or attribute = ''att3'') ORDER BY 1,2;');
20
20
21
-
SELECT*FROM crosstab2('SELECT rowid, attribute, val FROM ct where rowclass = ''group1'' ORDER BY 1,2;');
22
-
SELECT*FROM crosstab3('SELECT rowid, attribute, val FROM ct where rowclass = ''group1'' ORDER BY 1,2;');
23
-
SELECT*FROM crosstab4('SELECT rowid, attribute, val FROM ct where rowclass = ''group1'' ORDER BY 1,2;');
21
+
SELECT*FROM crosstab2('SELECT orarowid, attribute, val FROM ct where rowclass = ''group1'' ORDER BY 1,2;');
22
+
SELECT*FROM crosstab3('SELECT orarowid, attribute, val FROM ct where rowclass = ''group1'' ORDER BY 1,2;');
23
+
SELECT*FROM crosstab4('SELECT orarowid, attribute, val FROM ct where rowclass = ''group1'' ORDER BY 1,2;');
24
24
25
-
SELECT*FROM crosstab2('SELECT rowid, attribute, val FROM ct where rowclass = ''group2'' and (attribute = ''att1'' or attribute = ''att2'') ORDER BY 1,2;');
26
-
SELECT*FROM crosstab3('SELECT rowid, attribute, val FROM ct where rowclass = ''group2'' and (attribute = ''att1'' or attribute = ''att2'') ORDER BY 1,2;');
27
-
SELECT*FROM crosstab4('SELECT rowid, attribute, val FROM ct where rowclass = ''group2'' and (attribute = ''att1'' or attribute = ''att2'') ORDER BY 1,2;');
25
+
SELECT*FROM crosstab2('SELECT orarowid, attribute, val FROM ct where rowclass = ''group2'' and (attribute = ''att1'' or attribute = ''att2'') ORDER BY 1,2;');
26
+
SELECT*FROM crosstab3('SELECT orarowid, attribute, val FROM ct where rowclass = ''group2'' and (attribute = ''att1'' or attribute = ''att2'') ORDER BY 1,2;');
27
+
SELECT*FROM crosstab4('SELECT orarowid, attribute, val FROM ct where rowclass = ''group2'' and (attribute = ''att1'' or attribute = ''att2'') ORDER BY 1,2;');
28
28
29
-
SELECT*FROM crosstab2('SELECT rowid, attribute, val FROM ct where rowclass = ''group2'' ORDER BY 1,2;');
30
-
SELECT*FROM crosstab3('SELECT rowid, attribute, val FROM ct where rowclass = ''group2'' ORDER BY 1,2;');
31
-
SELECT*FROM crosstab4('SELECT rowid, attribute, val FROM ct where rowclass = ''group2'' ORDER BY 1,2;');
29
+
SELECT*FROM crosstab2('SELECT orarowid, attribute, val FROM ct where rowclass = ''group2'' ORDER BY 1,2;');
30
+
SELECT*FROM crosstab3('SELECT orarowid, attribute, val FROM ct where rowclass = ''group2'' ORDER BY 1,2;');
31
+
SELECT*FROM crosstab4('SELECT orarowid, attribute, val FROM ct where rowclass = ''group2'' ORDER BY 1,2;');
32
32
33
-
SELECT*FROM crosstab('SELECT rowid, attribute, val FROM ct where rowclass = ''group1'' ORDER BY 1,2;') AS c(rowid text, att1 text, att2 text);
34
-
SELECT*FROM crosstab('SELECT rowid, attribute, val FROM ct where rowclass = ''group1'' ORDER BY 1,2;') AS c(rowid text, att1 text, att2 text, att3 text);
35
-
SELECT*FROM crosstab('SELECT rowid, attribute, val FROM ct where rowclass = ''group1'' ORDER BY 1,2;') AS c(rowid text, att1 text, att2 text, att3 text, att4 text);
33
+
SELECT*FROM crosstab('SELECT orarowid, attribute, val FROM ct where rowclass = ''group1'' ORDER BY 1,2;') AS c(rowid text, att1 text, att2 text);
34
+
SELECT*FROM crosstab('SELECT orarowid, attribute, val FROM ct where rowclass = ''group1'' ORDER BY 1,2;') AS c(rowid text, att1 text, att2 text, att3 text);
35
+
SELECT*FROM crosstab('SELECT orarowid, attribute, val FROM ct where rowclass = ''group1'' ORDER BY 1,2;') AS c(rowid text, att1 text, att2 text, att3 text, att4 text);
36
36
37
37
-- check it works with OUT parameters, too
38
38
@@ -43,23 +43,23 @@ AS '$libdir/tablefunc','crosstab'
43
43
LANGUAGE C STABLE STRICT;
44
44
/
45
45
46
-
SELECT*FROM crosstab_out('SELECT rowid, attribute, val FROM ct where rowclass = ''group1'' ORDER BY 1,2;');
46
+
SELECT*FROM crosstab_out('SELECT orarowid, attribute, val FROM ct where rowclass = ''group1'' ORDER BY 1,2;');
47
47
48
48
-- check error reporting
49
-
SELECT*FROM crosstab('SELECT rowid, val FROM ct where rowclass = ''group1'' and (attribute = ''att2'' or attribute = ''att3'') ORDER BY 1,2;')
49
+
SELECT*FROM crosstab('SELECT orarowid, val FROM ct where rowclass = ''group1'' and (attribute = ''att2'' or attribute = ''att3'') ORDER BY 1,2;')
50
50
AS ct(row_name text, category_1 text, category_2 text);
51
-
SELECT*FROM crosstab('SELECT rowid, attribute, val FROM ct where rowclass = ''group1'' and (attribute = ''att2'' or attribute = ''att3'') ORDER BY 1,2;')
51
+
SELECT*FROM crosstab('SELECT orarowid, attribute, val FROM ct where rowclass = ''group1'' and (attribute = ''att2'' or attribute = ''att3'') ORDER BY 1,2;')
52
52
AS ct(row_name text);
53
-
SELECT*FROM crosstab('SELECT rowid, attribute, val FROM ct where rowclass = ''group1'' and (attribute = ''att2'' or attribute = ''att3'') ORDER BY 1,2;')
53
+
SELECT*FROM crosstab('SELECT orarowid, attribute, val FROM ct where rowclass = ''group1'' and (attribute = ''att2'' or attribute = ''att3'') ORDER BY 1,2;')
54
54
AS ct(row_name int, category_1 text, category_2 text);
55
-
SELECT*FROM crosstab('SELECT rowid, attribute, val FROM ct where rowclass = ''group1'' and (attribute = ''att2'' or attribute = ''att3'') ORDER BY 1,2;')
55
+
SELECT*FROM crosstab('SELECT orarowid, attribute, val FROM ct where rowclass = ''group1'' and (attribute = ''att2'' or attribute = ''att3'') ORDER BY 1,2;')
56
56
AS ct(row_name text, category_1 text, category_2 int);
57
57
58
58
--
59
59
-- hash based crosstab
60
60
--
61
61
62
-
createtablecth(id serial, rowidtext, rowdt pg_catalog.timestamp, attribute text, val text);
62
+
createtablecth(id serial, orarowidtext, rowdt pg_catalog.timestamp, attribute text, val text);
63
63
insert into cth values(DEFAULT,'test1','01 Mar 2003','temperature','42');
64
64
insert into cth values(DEFAULT,'test1','01 Mar 2003','test_result','PASS');
65
65
-- the next line is intentionally left commented and is therefore a "missing" attribute
@@ -77,71 +77,71 @@ insert into cth values(DEFAULT,NULL,'25 Oct 2007','volts','1.41234');
77
77
78
78
-- return attributes as plain text
79
79
SELECT*FROM crosstab(
80
-
'SELECT rowid, rowdt, attribute, val FROM cth ORDER BY 1',
80
+
'SELECT orarowid, rowdt, attribute, val FROM cth ORDER BY 1',
81
81
'SELECT DISTINCT attribute FROM cth ORDER BY 1')
82
82
AS c(rowid text, rowdt pg_catalog.timestamp, temperature text, test_result text, test_startdate text, volts text);
83
83
84
84
-- this time without rowdt
85
85
SELECT*FROM crosstab(
86
-
'SELECT rowid, attribute, val FROM cth ORDER BY 1',
86
+
'SELECT orarowid, attribute, val FROM cth ORDER BY 1',
87
87
'SELECT DISTINCT attribute FROM cth ORDER BY 1')
88
88
AS c(rowid text, temperature text, test_result text, test_startdate text, volts text);
89
89
90
90
-- convert attributes to specific datatypes
91
91
SELECT*FROM crosstab(
92
-
'SELECT rowid, rowdt, attribute, val FROM cth ORDER BY 1',
92
+
'SELECT orarowid, rowdt, attribute, val FROM cth ORDER BY 1',
93
93
'SELECT DISTINCT attribute FROM cth ORDER BY 1')
94
94
AS c(rowid text, rowdt pg_catalog.timestamp, temperature int4, test_result text, test_startdate pg_catalog.timestamp, volts float8);
95
95
96
96
-- source query and category query out of sync
97
97
SELECT*FROM crosstab(
98
-
'SELECT rowid, rowdt, attribute, val FROM cth ORDER BY 1',
98
+
'SELECT orarowid, rowdt, attribute, val FROM cth ORDER BY 1',
99
99
'SELECT DISTINCT attribute FROM cth WHERE attribute IN (''temperature'',''test_result'',''test_startdate'') ORDER BY 1')
100
100
AS c(rowid text, rowdt pg_catalog.timestamp, temperature int4, test_result text, test_startdate pg_catalog.timestamp);
101
101
102
102
-- if category query generates no rows, get expected error
103
103
SELECT*FROM crosstab(
104
-
'SELECT rowid, rowdt, attribute, val FROM cth ORDER BY 1',
104
+
'SELECT orarowid, rowdt, attribute, val FROM cth ORDER BY 1',
105
105
'SELECT DISTINCT attribute FROM cth WHERE attribute = ''a'' ORDER BY 1')
106
106
AS c(rowid text, rowdt pg_catalog.timestamp, temperature int4, test_result text, test_startdate pg_catalog.timestamp, volts float8);
107
107
108
108
-- if category query generates more than one column, get expected error
109
109
SELECT*FROM crosstab(
110
-
'SELECT rowid, rowdt, attribute, val FROM cth ORDER BY 1',
110
+
'SELECT orarowid, rowdt, attribute, val FROM cth ORDER BY 1',
111
111
'SELECT DISTINCT rowdt, attribute FROM cth ORDER BY 2')
112
112
AS c(rowid text, rowdt pg_catalog.timestamp, temperature int4, test_result text, test_startdate pg_catalog.timestamp, volts float8);
113
113
114
114
-- if category query generates a NULL value, get expected error
115
115
SELECT*FROM crosstab(
116
-
'SELECT rowid, rowdt, attribute, val FROM cth ORDER BY 1',
116
+
'SELECT orarowid, rowdt, attribute, val FROM cth ORDER BY 1',
117
117
'SELECT NULL::text')
118
118
AS c(rowid text, rowdt timestamp, temperature int4, test_result text, test_startdate timestamp, volts float8);
119
119
120
120
-- if source query returns zero rows, get zero rows returned
121
121
SELECT*FROM crosstab(
122
-
'SELECT rowid, rowdt, attribute, val FROM cth WHERE false ORDER BY 1',
122
+
'SELECT orarowid, rowdt, attribute, val FROM cth WHERE false ORDER BY 1',
123
123
'SELECT DISTINCT attribute FROM cth ORDER BY 1')
124
124
AS c(rowid text, rowdt timestamp, temperature text, test_result text, test_startdate text, volts text);
125
125
126
126
-- if source query returns zero rows, get zero rows returned even if category query generates no rows
127
127
SELECT*FROM crosstab(
128
-
'SELECT rowid, rowdt, attribute, val FROM cth WHERE false ORDER BY 1',
128
+
'SELECT orarowid, rowdt, attribute, val FROM cth WHERE false ORDER BY 1',
129
129
'SELECT DISTINCT attribute FROM cth WHERE false ORDER BY 1')
130
130
AS c(rowid text, rowdt pg_catalog.timestamp, temperature text, test_result text, test_startdate text, volts text);
131
131
132
132
-- check errors with inappropriate input rowtype
133
133
SELECT*FROM crosstab(
134
-
'SELECT rowid, attribute FROM cth ORDER BY 1',
134
+
'SELECT orarowid, attribute FROM cth ORDER BY 1',
135
135
'SELECT DISTINCT attribute FROM cth ORDER BY 1')
136
136
AS c(rowid text, temperature text, test_result text, test_startdate text, volts text);
137
137
SELECT*FROM crosstab(
138
-
'SELECT rowid, rowdt, rowdt, attribute, val FROM cth ORDER BY 1',
138
+
'SELECT orarowid, rowdt, rowdt, attribute, val FROM cth ORDER BY 1',
139
139
'SELECT DISTINCT attribute FROM cth ORDER BY 1')
140
140
AS c(rowid text, rowdt timestamp, temperature int4, test_result text, test_startdate timestamp, volts float8);
141
141
142
142
-- check errors with inappropriate result rowtype
143
143
SELECT*FROM crosstab(
144
-
'SELECT rowid, attribute, val FROM cth ORDER BY 1',
144
+
'SELECT orarowid, attribute, val FROM cth ORDER BY 1',
145
145
'SELECT DISTINCT attribute FROM cth ORDER BY 1')
146
146
AS c(rowid text);
147
147
@@ -158,13 +158,13 @@ LANGUAGE C STABLE STRICT;
158
158
/
159
159
160
160
SELECT*FROM crosstab_named(
161
-
'SELECT rowid, rowdt, attribute, val FROM cth ORDER BY 1',
161
+
'SELECT orarowid, rowdt, attribute, val FROM cth ORDER BY 1',
162
162
'SELECT DISTINCT attribute FROM cth ORDER BY 1');
163
163
164
164
-- check it works with OUT parameters
165
165
166
166
CREATEFUNCTIONcrosstab_out(text, text,
167
-
OUT rowidtext, OUT rowdt pg_catalog.timestamp,
167
+
OUT orarowidtext, OUT rowdt pg_catalog.timestamp,
168
168
OUT temperature int4, OUT test_result text,
169
169
OUT test_startdate pg_catalog.timestamp, OUT volts float8)
170
170
RETURNS setof record
@@ -173,7 +173,7 @@ LANGUAGE C STABLE STRICT;
173
173
/
174
174
175
175
SELECT*FROM crosstab_out(
176
-
'SELECT rowid, rowdt, attribute, val FROM cth ORDER BY 1',
176
+
'SELECT orarowid, rowdt, attribute, val FROM cth ORDER BY 1',
0 commit comments