aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/tests/postgresql/cases/select_implicit.out
blob: 507640d566709f85f743e2035e0117cdfa455347 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
--
-- SELECT_IMPLICIT
-- Test cases for queries with ordering terms missing from the target list.
-- This used to be called "junkfilter.sql".
-- The parser uses the term "resjunk" to handle these cases.
-- - thomas 1998-07-09
--
-- load test data
CREATE TABLE test_missing_target (a int, b int, c char(8), d char);
INSERT INTO test_missing_target VALUES (0, 1, 'XXXX', 'A');
INSERT INTO test_missing_target VALUES (1, 2, 'ABAB', 'b');
INSERT INTO test_missing_target VALUES (2, 2, 'ABAB', 'c');
INSERT INTO test_missing_target VALUES (3, 3, 'BBBB', 'D');
INSERT INTO test_missing_target VALUES (4, 3, 'BBBB', 'e');
INSERT INTO test_missing_target VALUES (5, 3, 'bbbb', 'F');
INSERT INTO test_missing_target VALUES (6, 4, 'cccc', 'g');
INSERT INTO test_missing_target VALUES (7, 4, 'cccc', 'h');
INSERT INTO test_missing_target VALUES (8, 4, 'CCCC', 'I');
INSERT INTO test_missing_target VALUES (9, 4, 'CCCC', 'j');
--   w/ existing GROUP BY target
SELECT c, count(*) FROM test_missing_target GROUP BY test_missing_target.c ORDER BY c;
    c     | count 
----------+-------
 ABAB     |     2
 BBBB     |     2
 CCCC     |     2
 XXXX     |     1
 bbbb     |     1
 cccc     |     2
(6 rows)

--   w/o existing GROUP BY target using a relation name in GROUP BY clause
SELECT count(*) FROM test_missing_target GROUP BY test_missing_target.c ORDER BY c;
 count 
-------
     2
     2
     2
     1
     1
     2
(6 rows)

--   w/o existing GROUP BY target and w/o existing same ORDER BY target
SELECT count(*) FROM test_missing_target GROUP BY b ORDER BY b;
 count 
-------
     1
     2
     3
     4
(4 rows)

--   w/ existing GROUP BY target using a relation name in target
SELECT test_missing_target.b, count(*)
  FROM test_missing_target GROUP BY b ORDER BY b;
 b | count 
---+-------
 1 |     1
 2 |     2
 3 |     3
 4 |     4
(4 rows)

--   w/o existing GROUP BY target
SELECT c FROM test_missing_target ORDER BY a;
    c     
----------
 XXXX    
 ABAB    
 ABAB    
 BBBB    
 BBBB    
 bbbb    
 cccc    
 cccc    
 CCCC    
 CCCC    
(10 rows)

--   w/o existing ORDER BY target
SELECT count(*) FROM test_missing_target GROUP BY b ORDER BY b desc;
 count 
-------
     4
     3
     2
     1
(4 rows)

--   group using reference number
SELECT count(*) FROM test_missing_target ORDER BY 1 desc;
 count 
-------
    10
(1 row)

--   order using reference number
SELECT c, count(*) FROM test_missing_target GROUP BY 1 ORDER BY 1;
    c     | count 
----------+-------
 ABAB     |     2
 BBBB     |     2
 CCCC     |     2
 XXXX     |     1
 bbbb     |     1
 cccc     |     2
(6 rows)

--   order expression w/ target under ambiguous condition
--   failure NOT expected
SELECT a/2, a/2 FROM test_missing_target
	ORDER BY a/2;
 ?column? | ?column? 
----------+----------
        0 |        0
        0 |        0
        1 |        1
        1 |        1
        2 |        2
        2 |        2
        3 |        3
        3 |        3
        4 |        4
        4 |        4
(10 rows)

--   group expression w/ target under ambiguous condition
--   failure NOT expected
SELECT a/2, a/2 FROM test_missing_target
	GROUP BY a/2 ORDER BY a/2;
 ?column? | ?column? 
----------+----------
        0 |        0
        1 |        1
        2 |        2
        3 |        3
        4 |        4
(5 rows)

--   group w/ existing GROUP BY target under ambiguous condition
SELECT x.b, count(*) FROM test_missing_target x, test_missing_target y
	WHERE x.a = y.a
	GROUP BY x.b ORDER BY x.b;
 b | count 
---+-------
 1 |     1
 2 |     2
 3 |     3
 4 |     4
(4 rows)

--   group w/o existing GROUP BY target under ambiguous condition
SELECT count(*) FROM test_missing_target x, test_missing_target y
	WHERE x.a = y.a
	GROUP BY x.b ORDER BY x.b;
 count 
-------
     1
     2
     3
     4
(4 rows)

--  Functions and expressions
--   w/ existing GROUP BY target
SELECT a%2, count(b) FROM test_missing_target
GROUP BY test_missing_target.a%2
ORDER BY test_missing_target.a%2;
 ?column? | count 
----------+-------
        0 |     5
        1 |     5
(2 rows)

--   w/o existing GROUP BY target using a relation name in GROUP BY clause
SELECT count(c) FROM test_missing_target
GROUP BY lower(test_missing_target.c)
ORDER BY lower(test_missing_target.c);
 count 
-------
     2
     3
     4
     1
(4 rows)

--   w/o existing GROUP BY target and w/o existing same ORDER BY target
SELECT count(b) FROM test_missing_target GROUP BY b/2 ORDER BY b/2;
 count 
-------
     1
     5
     4
(3 rows)

--   w/ existing GROUP BY target using a relation name in target
SELECT lower(test_missing_target.c), count(c)
  FROM test_missing_target GROUP BY lower(c) ORDER BY lower(c);
 lower | count 
-------+-------
 abab  |     2
 bbbb  |     3
 cccc  |     4
 xxxx  |     1
(4 rows)

--   w/o existing GROUP BY target
SELECT a FROM test_missing_target ORDER BY upper(d);
 a 
---
 0
 1
 2
 3
 4
 5
 6
 7
 8
 9
(10 rows)

--   w/o existing ORDER BY target
SELECT count(b) FROM test_missing_target
	GROUP BY (b + 1) / 2 ORDER BY (b + 1) / 2 desc;
 count 
-------
     7
     3
(2 rows)

--   group w/ existing GROUP BY target under ambiguous condition
SELECT x.b/2, count(x.b) FROM test_missing_target x, test_missing_target y
	WHERE x.a = y.a
	GROUP BY x.b/2 ORDER BY x.b/2;
 ?column? | count 
----------+-------
        0 |     1
        1 |     5
        2 |     4
(3 rows)

--   Cleanup
DROP TABLE test_missing_target;