OLD | NEW |
1 # 2010 July 16 | 1 # 2010 July 16 |
2 # | 2 # |
3 # The author disclaims copyright to this source code. In place of | 3 # The author disclaims copyright to this source code. In place of |
4 # a legal notice, here is a blessing: | 4 # a legal notice, here is a blessing: |
5 # | 5 # |
6 # May you do good and not evil. | 6 # May you do good and not evil. |
7 # May you find forgiveness for yourself and forgive others. | 7 # May you find forgiveness for yourself and forgive others. |
8 # May you share freely, never taking more than you give. | 8 # May you share freely, never taking more than you give. |
9 # | 9 # |
10 #*********************************************************************** | 10 #*********************************************************************** |
11 # | 11 # |
12 # This file implements tests to verify that the "testable statements" in | 12 # This file implements tests to verify that the "testable statements" in |
13 # the lang_select.html document are correct. | 13 # the lang_select.html document are correct. |
14 # | 14 # |
15 | 15 |
16 set testdir [file dirname $argv0] | 16 set testdir [file dirname $argv0] |
17 source $testdir/tester.tcl | 17 source $testdir/tester.tcl |
18 | 18 |
| 19 ifcapable !compound { |
| 20 finish_test |
| 21 return |
| 22 } |
| 23 |
19 do_execsql_test e_select-1.0 { | 24 do_execsql_test e_select-1.0 { |
20 CREATE TABLE t1(a, b); | 25 CREATE TABLE t1(a, b); |
21 INSERT INTO t1 VALUES('a', 'one'); | 26 INSERT INTO t1 VALUES('a', 'one'); |
22 INSERT INTO t1 VALUES('b', 'two'); | 27 INSERT INTO t1 VALUES('b', 'two'); |
23 INSERT INTO t1 VALUES('c', 'three'); | 28 INSERT INTO t1 VALUES('c', 'three'); |
24 | 29 |
25 CREATE TABLE t2(a, b); | 30 CREATE TABLE t2(a, b); |
26 INSERT INTO t2 VALUES('a', 'I'); | 31 INSERT INTO t2 VALUES('a', 'I'); |
27 INSERT INTO t2 VALUES('b', 'II'); | 32 INSERT INTO t2 VALUES('b', 'II'); |
28 INSERT INTO t2 VALUES('c', 'III'); | 33 INSERT INTO t2 VALUES('c', 'III'); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 foreach {tn2 joinop} [list 1 , 2 "CROSS JOIN" 3 "INNER JOIN"] { | 76 foreach {tn2 joinop} [list 1 , 2 "CROSS JOIN" 3 "INNER JOIN"] { |
72 set S [string map [list %JOIN% $joinop] $select] | 77 set S [string map [list %JOIN% $joinop] $select] |
73 uplevel do_execsql_test $tn.$tn2 [list $S] [list $res] | 78 uplevel do_execsql_test $tn.$tn2 [list $S] [list $res] |
74 } | 79 } |
75 } | 80 } |
76 | 81 |
77 #------------------------------------------------------------------------- | 82 #------------------------------------------------------------------------- |
78 # The following tests check that all paths on the syntax diagrams on | 83 # The following tests check that all paths on the syntax diagrams on |
79 # the lang_select.html page may be taken. | 84 # the lang_select.html page may be taken. |
80 # | 85 # |
81 # EVIDENCE-OF: R-18428-22111 -- syntax diagram join-constraint | 86 # -- syntax diagram join-constraint |
82 # | 87 # |
83 do_join_test e_select-0.1.1 { | 88 do_join_test e_select-0.1.1 { |
84 SELECT count(*) FROM t1 %JOIN% t2 ON (t1.a=t2.a) | 89 SELECT count(*) FROM t1 %JOIN% t2 ON (t1.a=t2.a) |
85 } {3} | 90 } {3} |
86 do_join_test e_select-0.1.2 { | 91 do_join_test e_select-0.1.2 { |
87 SELECT count(*) FROM t1 %JOIN% t2 USING (a) | 92 SELECT count(*) FROM t1 %JOIN% t2 USING (a) |
88 } {3} | 93 } {3} |
89 do_join_test e_select-0.1.3 { | 94 do_join_test e_select-0.1.3 { |
90 SELECT count(*) FROM t1 %JOIN% t2 | 95 SELECT count(*) FROM t1 %JOIN% t2 |
91 } {9} | 96 } {9} |
92 do_catchsql_test e_select-0.1.4 { | 97 do_catchsql_test e_select-0.1.4 { |
93 SELECT count(*) FROM t1, t2 ON (t1.a=t2.a) USING (a) | 98 SELECT count(*) FROM t1, t2 ON (t1.a=t2.a) USING (a) |
94 } {1 {cannot have both ON and USING clauses in the same join}} | 99 } {1 {cannot have both ON and USING clauses in the same join}} |
95 do_catchsql_test e_select-0.1.5 { | 100 do_catchsql_test e_select-0.1.5 { |
96 SELECT count(*) FROM t1, t2 USING (a) ON (t1.a=t2.a) | 101 SELECT count(*) FROM t1, t2 USING (a) ON (t1.a=t2.a) |
97 } {1 {near "ON": syntax error}} | 102 } {1 {near "ON": syntax error}} |
98 | 103 |
99 # EVIDENCE-OF: R-44854-11739 -- syntax diagram select-core | 104 # -- syntax diagram select-core |
100 # | 105 # |
101 # 0: SELECT ... | 106 # 0: SELECT ... |
102 # 1: SELECT DISTINCT ... | 107 # 1: SELECT DISTINCT ... |
103 # 2: SELECT ALL ... | 108 # 2: SELECT ALL ... |
104 # | 109 # |
105 # 0: No FROM clause | 110 # 0: No FROM clause |
106 # 1: Has FROM clause | 111 # 1: Has FROM clause |
107 # | 112 # |
108 # 0: No WHERE clause | 113 # 0: No WHERE clause |
109 # 1: Has WHERE clause | 114 # 1: Has WHERE clause |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 {1 c 1 b} | 219 {1 c 1 b} |
215 2112.1 "SELECT ALL count(*), max(a) FROM t1 WHERE a!='b' | 220 2112.1 "SELECT ALL count(*), max(a) FROM t1 WHERE a!='b' |
216 GROUP BY b HAVING count(*)=1" { | 221 GROUP BY b HAVING count(*)=1" { |
217 1 a 1 c | 222 1 a 1 c |
218 } | 223 } |
219 2112.2 "SELECT ALL count(*), max(a) FROM t1 | 224 2112.2 "SELECT ALL count(*), max(a) FROM t1 |
220 WHERE 0 GROUP BY b HAVING count(*)=2" { } | 225 WHERE 0 GROUP BY b HAVING count(*)=2" { } |
221 } | 226 } |
222 | 227 |
223 | 228 |
224 # EVIDENCE-OF: R-23316-20169 -- syntax diagram result-column | 229 # -- syntax diagram result-column |
225 # | 230 # |
226 do_select_tests e_select-0.3 { | 231 do_select_tests e_select-0.3 { |
227 1 "SELECT * FROM t1" {a one b two c three} | 232 1 "SELECT * FROM t1" {a one b two c three} |
228 2 "SELECT t1.* FROM t1" {a one b two c three} | 233 2 "SELECT t1.* FROM t1" {a one b two c three} |
229 3 "SELECT 'x'||a||'x' FROM t1" {xax xbx xcx} | 234 3 "SELECT 'x'||a||'x' FROM t1" {xax xbx xcx} |
230 4 "SELECT 'x'||a||'x' alias FROM t1" {xax xbx xcx} | 235 4 "SELECT 'x'||a||'x' alias FROM t1" {xax xbx xcx} |
231 5 "SELECT 'x'||a||'x' AS alias FROM t1" {xax xbx xcx} | 236 5 "SELECT 'x'||a||'x' AS alias FROM t1" {xax xbx xcx} |
232 } | 237 } |
233 | 238 |
234 # EVIDENCE-OF: R-41233-21397 -- syntax diagram join-source | 239 # -- syntax diagram join-source |
235 # | 240 # |
236 # EVIDENCE-OF: R-45040-11121 -- syntax diagram join-op | 241 # -- syntax diagram join-op |
237 # | 242 # |
238 do_select_tests e_select-0.4 { | 243 do_select_tests e_select-0.4 { |
239 1 "SELECT t1.rowid FROM t1" {1 2 3} | 244 1 "SELECT t1.rowid FROM t1" {1 2 3} |
240 2 "SELECT t1.rowid FROM t1,t2" {1 1 1 2 2 2 3 3 3} | 245 2 "SELECT t1.rowid FROM t1,t2" {1 1 1 2 2 2 3 3 3} |
241 3 "SELECT t1.rowid FROM t1,t2,t3" {1 1 1 1 1 1 2 2 2 2 2 2 3 3 3 3 3 3} | 246 3 "SELECT t1.rowid FROM t1,t2,t3" {1 1 1 1 1 1 2 2 2 2 2 2 3 3 3 3 3 3} |
242 | 247 |
243 4 "SELECT t1.rowid FROM t1" {1 2 3} | 248 4 "SELECT t1.rowid FROM t1" {1 2 3} |
244 5 "SELECT t1.rowid FROM t1 JOIN t2" {1 1 1 2 2 2 3 3 3} | 249 5 "SELECT t1.rowid FROM t1 JOIN t2" {1 1 1 2 2 2 3 3 3} |
245 6 "SELECT t1.rowid FROM t1 JOIN t2 JOIN t3" | 250 6 "SELECT t1.rowid FROM t1 JOIN t2 JOIN t3" |
246 {1 1 1 1 1 1 2 2 2 2 2 2 3 3 3 3 3 3} | 251 {1 1 1 1 1 1 2 2 2 2 2 2 3 3 3 3 3 3} |
247 | 252 |
248 7 "SELECT t1.rowid FROM t1 NATURAL JOIN t3" {1 2} | 253 7 "SELECT t1.rowid FROM t1 NATURAL JOIN t3" {1 2} |
249 8 "SELECT t1.rowid FROM t1 NATURAL LEFT OUTER JOIN t3" {1 2 3} | 254 8 "SELECT t1.rowid FROM t1 NATURAL LEFT OUTER JOIN t3" {1 2 3} |
250 9 "SELECT t1.rowid FROM t1 NATURAL LEFT JOIN t3" {1 2 3} | 255 9 "SELECT t1.rowid FROM t1 NATURAL LEFT JOIN t3" {1 2 3} |
251 10 "SELECT t1.rowid FROM t1 NATURAL INNER JOIN t3" {1 2} | 256 10 "SELECT t1.rowid FROM t1 NATURAL INNER JOIN t3" {1 2} |
252 11 "SELECT t1.rowid FROM t1 NATURAL CROSS JOIN t3" {1 2} | 257 11 "SELECT t1.rowid FROM t1 NATURAL CROSS JOIN t3" {1 2} |
253 | 258 |
254 12 "SELECT t1.rowid FROM t1 JOIN t3" {1 1 2 2 3 3} | 259 12 "SELECT t1.rowid FROM t1 JOIN t3" {1 1 2 2 3 3} |
255 13 "SELECT t1.rowid FROM t1 LEFT OUTER JOIN t3" {1 1 2 2 3 3} | 260 13 "SELECT t1.rowid FROM t1 LEFT OUTER JOIN t3" {1 1 2 2 3 3} |
256 14 "SELECT t1.rowid FROM t1 LEFT JOIN t3" {1 1 2 2 3 3} | 261 14 "SELECT t1.rowid FROM t1 LEFT JOIN t3" {1 1 2 2 3 3} |
257 15 "SELECT t1.rowid FROM t1 INNER JOIN t3" {1 1 2 2 3 3} | 262 15 "SELECT t1.rowid FROM t1 INNER JOIN t3" {1 1 2 2 3 3} |
258 16 "SELECT t1.rowid FROM t1 CROSS JOIN t3" {1 1 2 2 3 3} | 263 16 "SELECT t1.rowid FROM t1 CROSS JOIN t3" {1 1 2 2 3 3} |
259 } | 264 } |
260 | 265 |
261 # EVIDENCE-OF: R-56911-63533 -- syntax diagram compound-operator | 266 # -- syntax diagram compound-operator |
262 # | 267 # |
263 do_select_tests e_select-0.5 { | 268 do_select_tests e_select-0.5 { |
264 1 "SELECT rowid FROM t1 UNION ALL SELECT rowid+2 FROM t4" {1 2 3 3 4} | 269 1 "SELECT rowid FROM t1 UNION ALL SELECT rowid+2 FROM t4" {1 2 3 3 4} |
265 2 "SELECT rowid FROM t1 UNION SELECT rowid+2 FROM t4" {1 2 3 4} | 270 2 "SELECT rowid FROM t1 UNION SELECT rowid+2 FROM t4" {1 2 3 4} |
266 3 "SELECT rowid FROM t1 INTERSECT SELECT rowid+2 FROM t4" {3} | 271 3 "SELECT rowid FROM t1 INTERSECT SELECT rowid+2 FROM t4" {3} |
267 4 "SELECT rowid FROM t1 EXCEPT SELECT rowid+2 FROM t4" {1 2} | 272 4 "SELECT rowid FROM t1 EXCEPT SELECT rowid+2 FROM t4" {1 2} |
268 } | 273 } |
269 | 274 |
270 # EVIDENCE-OF: R-60388-27458 -- syntax diagram ordering-term | 275 # -- syntax diagram ordering-term |
271 # | 276 # |
272 do_select_tests e_select-0.6 { | 277 do_select_tests e_select-0.6 { |
273 1 "SELECT b||a FROM t1 ORDER BY b||a" {onea threec twob} | 278 1 "SELECT b||a FROM t1 ORDER BY b||a" {onea threec twob} |
274 2 "SELECT b||a FROM t1 ORDER BY (b||a) COLLATE nocase" {onea threec twob} | 279 2 "SELECT b||a FROM t1 ORDER BY (b||a) COLLATE nocase" {onea threec twob} |
275 3 "SELECT b||a FROM t1 ORDER BY (b||a) ASC" {onea threec twob} | 280 3 "SELECT b||a FROM t1 ORDER BY (b||a) ASC" {onea threec twob} |
276 4 "SELECT b||a FROM t1 ORDER BY (b||a) DESC" {twob threec onea} | 281 4 "SELECT b||a FROM t1 ORDER BY (b||a) DESC" {twob threec onea} |
277 } | 282 } |
278 | 283 |
279 # EVIDENCE-OF: R-36494-33519 -- syntax diagram select-stmt | 284 # -- syntax diagram select-stmt |
280 # | 285 # |
281 do_select_tests e_select-0.7 { | 286 do_select_tests e_select-0.7 { |
282 1 "SELECT * FROM t1" {a one b two c three} | 287 1 "SELECT * FROM t1" {a one b two c three} |
283 2 "SELECT * FROM t1 ORDER BY b" {a one c three b two} | 288 2 "SELECT * FROM t1 ORDER BY b" {a one c three b two} |
284 3 "SELECT * FROM t1 ORDER BY b, a" {a one c three b two} | 289 3 "SELECT * FROM t1 ORDER BY b, a" {a one c three b two} |
285 | 290 |
286 4 "SELECT * FROM t1 LIMIT 10" {a one b two c three} | 291 4 "SELECT * FROM t1 LIMIT 10" {a one b two c three} |
287 5 "SELECT * FROM t1 LIMIT 10 OFFSET 5" {} | 292 5 "SELECT * FROM t1 LIMIT 10 OFFSET 5" {} |
288 6 "SELECT * FROM t1 LIMIT 10, 5" {} | 293 6 "SELECT * FROM t1 LIMIT 10, 5" {} |
289 | 294 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 # | 326 # |
322 do_select_tests e_select-1.1 { | 327 do_select_tests e_select-1.1 { |
323 1 "SELECT 'abc'" {abc} | 328 1 "SELECT 'abc'" {abc} |
324 2 "SELECT 'abc' WHERE NULL" {} | 329 2 "SELECT 'abc' WHERE NULL" {} |
325 3 "SELECT NULL" {{}} | 330 3 "SELECT NULL" {{}} |
326 4 "SELECT count(*)" {1} | 331 4 "SELECT count(*)" {1} |
327 5 "SELECT count(*) WHERE 0" {0} | 332 5 "SELECT count(*) WHERE 0" {0} |
328 6 "SELECT count(*) WHERE 1" {1} | 333 6 "SELECT count(*) WHERE 1" {1} |
329 } | 334 } |
330 | 335 |
331 # EVIDENCE-OF: R-48114-33255 If there is only a single table in the | 336 # EVIDENCE-OF: R-45424-07352 If there is only a single table or subquery |
332 # join-source following the FROM clause, then the input data used by the | 337 # in the FROM clause, then the input data used by the SELECT statement |
333 # SELECT statement is the contents of the named table. | 338 # is the contents of the named table. |
334 # | 339 # |
335 # The results of the SELECT queries suggest that they are operating on the | 340 # The results of the SELECT queries suggest that they are operating on the |
336 # contents of the table 'xx'. | 341 # contents of the table 'xx'. |
337 # | 342 # |
338 do_execsql_test e_select-1.2.0 { | 343 do_execsql_test e_select-1.2.0 { |
339 CREATE TABLE xx(x, y); | 344 CREATE TABLE xx(x, y); |
340 INSERT INTO xx VALUES('IiJlsIPepMuAhU', X'10B00B897A15BAA02E3F98DCE8F2'); | 345 INSERT INTO xx VALUES('IiJlsIPepMuAhU', X'10B00B897A15BAA02E3F98DCE8F2'); |
341 INSERT INTO xx VALUES(NULL, -16.87); | 346 INSERT INTO xx VALUES(NULL, -16.87); |
342 INSERT INTO xx VALUES(-17.89, 'linguistically'); | 347 INSERT INTO xx VALUES(-17.89, 'linguistically'); |
343 } {} | 348 } {} |
344 do_select_tests e_select-1.2 { | 349 do_select_tests e_select-1.2 { |
345 1 "SELECT quote(x), quote(y) FROM xx" { | 350 1 "SELECT quote(x), quote(y) FROM xx" { |
346 'IiJlsIPepMuAhU' X'10B00B897A15BAA02E3F98DCE8F2' | 351 'IiJlsIPepMuAhU' X'10B00B897A15BAA02E3F98DCE8F2' |
347 NULL -16.87 | 352 NULL -16.87 |
348 -17.89 'linguistically' | 353 -17.89 'linguistically' |
349 } | 354 } |
350 | 355 |
351 2 "SELECT count(*), count(x), count(y) FROM xx" {3 2 3} | 356 2 "SELECT count(*), count(x), count(y) FROM xx" {3 2 3} |
352 3 "SELECT sum(x), sum(y) FROM xx" {-17.89 -16.87} | 357 3 "SELECT sum(x), sum(y) FROM xx" {-17.89 -16.87} |
353 } | 358 } |
354 | 359 |
355 # EVIDENCE-OF: R-23593-12456 If there is more than one table specified | 360 # EVIDENCE-OF: R-28355-09804 If there is more than one table or subquery |
356 # as part of the join-source following the FROM keyword, then the | 361 # in FROM clause then the contents of all tables and/or subqueries are |
357 # contents of each named table are joined into a single dataset for the | 362 # joined into a single dataset for the simple SELECT statement to |
358 # simple SELECT statement to operate on. | 363 # operate on. |
359 # | 364 # |
360 # There are more detailed tests for subsequent requirements that add | 365 # There are more detailed tests for subsequent requirements that add |
361 # more detail to this idea. We just add a single test that shows that | 366 # more detail to this idea. We just add a single test that shows that |
362 # data is coming from each of the three tables following the FROM clause | 367 # data is coming from each of the three tables following the FROM clause |
363 # here to show that the statement, vague as it is, is not incorrect. | 368 # here to show that the statement, vague as it is, is not incorrect. |
364 # | 369 # |
365 do_select_tests e_select-1.3 { | 370 do_select_tests e_select-1.3 { |
366 1 "SELECT * FROM t1, t2, t3" { | 371 1 "SELECT * FROM t1, t2, t3" { |
367 a one a I a 1 a one a I b 2 a one b II a 1 | 372 a one a I a 1 a one a I b 2 a one b II a 1 |
368 a one b II b 2 a one c III a 1 a one c III b 2 | 373 a one b II b 2 a one c III a 1 a one c III b 2 |
369 b two a I a 1 b two a I b 2 b two b II a 1 | 374 b two a I a 1 b two a I b 2 b two b II a 1 |
370 b two b II b 2 b two c III a 1 b two c III b 2 | 375 b two b II b 2 b two c III a 1 b two c III b 2 |
371 c three a I a 1 c three a I b 2 c three b II a 1 | 376 c three a I a 1 c three a I b 2 c three b II a 1 |
372 c three b II b 2 c three c III a 1 c three c III b 2 | 377 c three b II b 2 c three c III a 1 c three c III b 2 |
373 } | 378 } |
374 } | 379 } |
375 | 380 |
376 # | 381 # |
377 # The following block of tests - e_select-1.4.* - test that the description | 382 # The following block of tests - e_select-1.4.* - test that the description |
378 # of cartesian joins in the SELECT documentation is consistent with SQLite. | 383 # of cartesian joins in the SELECT documentation is consistent with SQLite. |
379 # In doing so, we test the following three requirements as a side-effect: | 384 # In doing so, we test the following three requirements as a side-effect: |
380 # | 385 # |
381 # EVIDENCE-OF: R-46122-14930 If the join-op is "CROSS JOIN", "INNER | 386 # EVIDENCE-OF: R-49872-03192 If the join-operator is "CROSS JOIN", |
382 # JOIN", "JOIN" or a comma (",") and there is no ON or USING clause, | 387 # "INNER JOIN", "JOIN" or a comma (",") and there is no ON or USING |
383 # then the result of the join is simply the cartesian product of the | 388 # clause, then the result of the join is simply the cartesian product of |
384 # left and right-hand datasets. | 389 # the left and right-hand datasets. |
385 # | 390 # |
386 # The tests are built on this assertion. Really, they test that the output | 391 # The tests are built on this assertion. Really, they test that the output |
387 # of a CROSS JOIN, JOIN, INNER JOIN or "," join matches the expected result | 392 # of a CROSS JOIN, JOIN, INNER JOIN or "," join matches the expected result |
388 # of calculating the cartesian product of the left and right-hand datasets. | 393 # of calculating the cartesian product of the left and right-hand datasets. |
389 # | 394 # |
390 # EVIDENCE-OF: R-46256-57243 There is no difference between the "INNER | 395 # EVIDENCE-OF: R-46256-57243 There is no difference between the "INNER |
391 # JOIN", "JOIN" and "," join operators. | 396 # JOIN", "JOIN" and "," join operators. |
392 # | 397 # |
393 # EVIDENCE-OF: R-07544-24155 The "CROSS JOIN" join operator produces the | 398 # EVIDENCE-OF: R-25071-21202 The "CROSS JOIN" join operator produces the |
394 # same data as the "INNER JOIN", "JOIN" and "," operators | 399 # same result as the "INNER JOIN", "JOIN" and "," operators |
395 # | 400 # |
396 # All tests are run 4 times, with the only difference in each run being | 401 # All tests are run 4 times, with the only difference in each run being |
397 # which of the 4 equivalent cartesian product join operators are used. | 402 # which of the 4 equivalent cartesian product join operators are used. |
398 # Since the output data is the same in all cases, we consider that this | 403 # Since the output data is the same in all cases, we consider that this |
399 # qualifies as testing the two statements above. | 404 # qualifies as testing the two statements above. |
400 # | 405 # |
401 do_execsql_test e_select-1.4.0 { | 406 do_execsql_test e_select-1.4.0 { |
402 CREATE TABLE x1(a, b); | 407 CREATE TABLE x1(a, b); |
403 CREATE TABLE x2(c, d, e); | 408 CREATE TABLE x2(c, d, e); |
404 CREATE TABLE x3(f, g, h, i); | 409 CREATE TABLE x3(f, g, h, i); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 | 443 |
439 do_join_test e_select-1.4.1.4 { | 444 do_join_test e_select-1.4.1.4 { |
440 SELECT * FROM x2 %JOIN% x3 LIMIT 1 | 445 SELECT * FROM x2 %JOIN% x3 LIMIT 1 |
441 } [concat {-60.06 {} {}} {-39.24 {} encompass -1}] | 446 } [concat {-60.06 {} {}} {-39.24 {} encompass -1}] |
442 | 447 |
443 # EVIDENCE-OF: R-44414-54710 There is a row in the cartesian product | 448 # EVIDENCE-OF: R-44414-54710 There is a row in the cartesian product |
444 # dataset formed by combining each unique combination of a row from the | 449 # dataset formed by combining each unique combination of a row from the |
445 # left-hand and right-hand datasets. | 450 # left-hand and right-hand datasets. |
446 # | 451 # |
447 do_join_test e_select-1.4.2.1 { | 452 do_join_test e_select-1.4.2.1 { |
448 SELECT * FROM x2 %JOIN% x3 | 453 SELECT * FROM x2 %JOIN% x3 ORDER BY +c, +f |
449 } [list -60.06 {} {} -39.24 {} encompass -1 \ | 454 } [list -60.06 {} {} -39.24 {} encompass -1 \ |
| 455 -60.06 {} {} alerting {} -93.79 {} \ |
| 456 -60.06 {} {} coldest -96 dramatists 82.3 \ |
| 457 -60.06 {} {} conducting -87.24 37.56 {} \ |
450 -60.06 {} {} presenting 51 reformation dignified \ | 458 -60.06 {} {} presenting 51 reformation dignified \ |
451 -60.06 {} {} conducting -87.24 37.56 {} \ | |
452 -60.06 {} {} coldest -96 dramatists 82.3 \ | |
453 -60.06 {} {} alerting {} -93.79 {} \ | |
454 -58 {} 1.21 -39.24 {} encompass -1 \ | 459 -58 {} 1.21 -39.24 {} encompass -1 \ |
| 460 -58 {} 1.21 alerting {} -93.79 {} \ |
| 461 -58 {} 1.21 coldest -96 dramatists 82.3 \ |
| 462 -58 {} 1.21 conducting -87.24 37.56 {} \ |
455 -58 {} 1.21 presenting 51 reformation dignified \ | 463 -58 {} 1.21 presenting 51 reformation dignified \ |
456 -58 {} 1.21 conducting -87.24 37.56 {} \ | |
457 -58 {} 1.21 coldest -96 dramatists 82.3 \ | |
458 -58 {} 1.21 alerting {} -93.79 {} \ | |
459 ] | 464 ] |
460 # TODO: Come back and add a few more like the above. | 465 # TODO: Come back and add a few more like the above. |
461 | 466 |
462 # EVIDENCE-OF: R-20659-43267 In other words, if the left-hand dataset | 467 # EVIDENCE-OF: R-18439-38548 In other words, if the left-hand dataset |
463 # consists of Nlhs rows of Mlhs columns, and the right-hand dataset of | 468 # consists of Nleft rows of Mleft columns, and the right-hand dataset of |
464 # Nrhs rows of Mrhs columns, then the cartesian product is a dataset of | 469 # Nright rows of Mright columns, then the cartesian product is a dataset |
465 # Nlhs.Nrhs rows, each containing Mlhs+Mrhs columns. | 470 # of Nleft×Nright rows, each containing Mleft+Mright columns. |
466 # | 471 # |
467 # x1, x2 (Nlhs=3, Nrhs=2) (Mlhs=2, Mrhs=3) | 472 # x1, x2 (Nlhs=3, Nrhs=2) (Mlhs=2, Mrhs=3) |
468 do_join_test e_select-1.4.3.1 { | 473 do_join_test e_select-1.4.3.1 { |
469 SELECT count(*) FROM x1 %JOIN% x2 | 474 SELECT count(*) FROM x1 %JOIN% x2 |
470 } [expr 3*2] | 475 } [expr 3*2] |
471 do_test e_select-1.4.3.2 { | 476 do_test e_select-1.4.3.2 { |
472 expr {[llength [execsql {SELECT * FROM x1, x2}]] / 6} | 477 expr {[llength [execsql {SELECT * FROM x1, x2}]] / 6} |
473 } [expr 2+3] | 478 } [expr 2+3] |
474 | 479 |
475 # x2, x3 (Nlhs=2, Nrhs=5) (Mlhs=3, Mrhs=4) | 480 # x2, x3 (Nlhs=2, Nrhs=5) (Mlhs=3, Mrhs=4) |
(...skipping 25 matching lines...) Expand all Loading... |
501 do_execsql_test e_select-1.4.4.1 { SELECT * FROM t1, t2 } $t1_cross_t2 | 506 do_execsql_test e_select-1.4.4.1 { SELECT * FROM t1, t2 } $t1_cross_t2 |
502 do_execsql_test e_select-1.4.4.2 { SELECT * FROM t1 AS x, t1 AS y} $t1_cross_t1 | 507 do_execsql_test e_select-1.4.4.2 { SELECT * FROM t1 AS x, t1 AS y} $t1_cross_t1 |
503 | 508 |
504 do_select_tests e_select-1.4.5 [list \ | 509 do_select_tests e_select-1.4.5 [list \ |
505 1 { SELECT * FROM t1 CROSS JOIN t2 } $t1_cross_t2 \ | 510 1 { SELECT * FROM t1 CROSS JOIN t2 } $t1_cross_t2 \ |
506 2 { SELECT * FROM t1 AS y CROSS JOIN t1 AS x } $t1_cross_t1 \ | 511 2 { SELECT * FROM t1 AS y CROSS JOIN t1 AS x } $t1_cross_t1 \ |
507 3 { SELECT * FROM t1 INNER JOIN t2 } $t1_cross_t2 \ | 512 3 { SELECT * FROM t1 INNER JOIN t2 } $t1_cross_t2 \ |
508 4 { SELECT * FROM t1 AS y INNER JOIN t1 AS x } $t1_cross_t1 \ | 513 4 { SELECT * FROM t1 AS y INNER JOIN t1 AS x } $t1_cross_t1 \ |
509 ] | 514 ] |
510 | 515 |
511 | 516 # EVIDENCE-OF: R-38465-03616 If there is an ON clause then the ON |
512 # EVIDENCE-OF: R-22775-56496 If there is an ON clause specified, then | 517 # expression is evaluated for each row of the cartesian product as a |
513 # the ON expression is evaluated for each row of the cartesian product | 518 # boolean expression. Only rows for which the expression evaluates to |
514 # as a boolean expression. All rows for which the expression evaluates | 519 # true are included from the dataset. |
515 # to false are excluded from the dataset. | |
516 # | 520 # |
517 foreach {tn select res} [list \ | 521 foreach {tn select res} [list \ |
518 1 { SELECT * FROM t1 %JOIN% t2 ON (1) } $t1_cross_t2 \ | 522 1 { SELECT * FROM t1 %JOIN% t2 ON (1) } $t1_cross_t2 \ |
519 2 { SELECT * FROM t1 %JOIN% t2 ON (0) } [list] \ | 523 2 { SELECT * FROM t1 %JOIN% t2 ON (0) } [list] \ |
520 3 { SELECT * FROM t1 %JOIN% t2 ON (NULL) } [list] \ | 524 3 { SELECT * FROM t1 %JOIN% t2 ON (NULL) } [list] \ |
521 4 { SELECT * FROM t1 %JOIN% t2 ON ('abc') } [list] \ | 525 4 { SELECT * FROM t1 %JOIN% t2 ON ('abc') } [list] \ |
522 5 { SELECT * FROM t1 %JOIN% t2 ON ('1ab') } $t1_cross_t2 \ | 526 5 { SELECT * FROM t1 %JOIN% t2 ON ('1ab') } $t1_cross_t2 \ |
523 6 { SELECT * FROM t1 %JOIN% t2 ON (0.9) } $t1_cross_t2 \ | 527 6 { SELECT * FROM t1 %JOIN% t2 ON (0.9) } $t1_cross_t2 \ |
524 7 { SELECT * FROM t1 %JOIN% t2 ON ('0.9') } $t1_cross_t2 \ | 528 7 { SELECT * FROM t1 %JOIN% t2 ON ('0.9') } $t1_cross_t2 \ |
525 8 { SELECT * FROM t1 %JOIN% t2 ON (0.0) } [list] \ | 529 8 { SELECT * FROM t1 %JOIN% t2 ON (0.0) } [list] \ |
526 \ | 530 \ |
527 9 { SELECT t1.b, t2.b FROM t1 %JOIN% t2 ON (t1.a = t2.a) } \ | 531 9 { SELECT t1.b, t2.b FROM t1 %JOIN% t2 ON (t1.a = t2.a) } \ |
528 {one I two II three III} \ | 532 {one I two II three III} \ |
529 10 { SELECT t1.b, t2.b FROM t1 %JOIN% t2 ON (t1.a = 'a') } \ | 533 10 { SELECT t1.b, t2.b FROM t1 %JOIN% t2 ON (t1.a = 'a') } \ |
530 {one I one II one III} \ | 534 {one I one II one III} \ |
531 11 { SELECT t1.b, t2.b | 535 11 { SELECT t1.b, t2.b |
532 FROM t1 %JOIN% t2 ON (CASE WHEN t1.a = 'a' THEN NULL ELSE 1 END) } \ | 536 FROM t1 %JOIN% t2 ON (CASE WHEN t1.a = 'a' THEN NULL ELSE 1 END) } \ |
533 {two I two II two III three I three II three III} \ | 537 {two I two II two III three I three II three III} \ |
534 ] { | 538 ] { |
535 do_join_test e_select-1.3.$tn $select $res | 539 do_join_test e_select-1.3.$tn $select $res |
536 } | 540 } |
537 | 541 |
538 # EVIDENCE-OF: R-63358-54862 If there is a USING clause specified as | 542 # EVIDENCE-OF: R-49933-05137 If there is a USING clause then each of the |
539 # part of the join-constraint, then each of the column names specified | 543 # column names specified must exist in the datasets to both the left and |
540 # must exist in the datasets to both the left and right of the join-op. | 544 # right of the join-operator. |
541 # | 545 # |
542 do_select_tests e_select-1.4 -error { | 546 do_select_tests e_select-1.4 -error { |
543 cannot join using column %s - column not present in both tables | 547 cannot join using column %s - column not present in both tables |
544 } { | 548 } { |
545 1 { SELECT * FROM t1, t3 USING (b) } "b" | 549 1 { SELECT * FROM t1, t3 USING (b) } "b" |
546 2 { SELECT * FROM t3, t1 USING (c) } "c" | 550 2 { SELECT * FROM t3, t1 USING (c) } "c" |
547 3 { SELECT * FROM t3, (SELECT a AS b, b AS c FROM t1) USING (a) } "a" | 551 3 { SELECT * FROM t3, (SELECT a AS b, b AS c FROM t1) USING (a) } "a" |
548 } | 552 } |
549 | 553 |
550 # EVIDENCE-OF: R-55987-04584 For each pair of namesake columns, the | 554 # EVIDENCE-OF: R-22776-52830 For each pair of named columns, the |
551 # expression "lhs.X = rhs.X" is evaluated for each row of the cartesian | 555 # expression "lhs.X = rhs.X" is evaluated for each row of the cartesian |
552 # product as a boolean expression. All rows for which one or more of the | 556 # product as a boolean expression. Only rows for which all such |
553 # expressions evaluates to false are excluded from the result set. | 557 # expressions evaluates to true are included from the result set. |
554 # | 558 # |
555 do_select_tests e_select-1.5 { | 559 do_select_tests e_select-1.5 { |
556 1 { SELECT * FROM t1, t3 USING (a) } {a one 1 b two 2} | 560 1 { SELECT * FROM t1, t3 USING (a) } {a one 1 b two 2} |
557 2 { SELECT * FROM t3, t4 USING (a,c) } {b 2} | 561 2 { SELECT * FROM t3, t4 USING (a,c) } {b 2} |
558 } | 562 } |
559 | 563 |
560 # EVIDENCE-OF: R-54046-48600 When comparing values as a result of a | 564 # EVIDENCE-OF: R-54046-48600 When comparing values as a result of a |
561 # USING clause, the normal rules for handling affinities, collation | 565 # USING clause, the normal rules for handling affinities, collation |
562 # sequences and NULL values in comparisons apply. | 566 # sequences and NULL values in comparisons apply. |
563 # | 567 # |
564 # EVIDENCE-OF: R-35466-18578 The column from the dataset on the | 568 # EVIDENCE-OF: R-38422-04402 The column from the dataset on the |
565 # left-hand side of the join operator is considered to be on the | 569 # left-hand side of the join-operator is considered to be on the |
566 # left-hand side of the comparison operator (=) for the purposes of | 570 # left-hand side of the comparison operator (=) for the purposes of |
567 # collation sequence and affinity precedence. | 571 # collation sequence and affinity precedence. |
568 # | 572 # |
569 do_execsql_test e_select-1.6.0 { | 573 do_execsql_test e_select-1.6.0 { |
570 CREATE TABLE t5(a COLLATE nocase, b COLLATE binary); | 574 CREATE TABLE t5(a COLLATE nocase, b COLLATE binary); |
571 INSERT INTO t5 VALUES('AA', 'cc'); | 575 INSERT INTO t5 VALUES('AA', 'cc'); |
572 INSERT INTO t5 VALUES('BB', 'dd'); | 576 INSERT INTO t5 VALUES('BB', 'dd'); |
573 INSERT INTO t5 VALUES(NULL, NULL); | 577 INSERT INTO t5 VALUES(NULL, NULL); |
574 CREATE TABLE t6(a COLLATE binary, b COLLATE nocase); | 578 CREATE TABLE t6(a COLLATE binary, b COLLATE nocase); |
575 INSERT INTO t6 VALUES('aa', 'cc'); | 579 INSERT INTO t6 VALUES('aa', 'cc'); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 | 614 |
611 4a { SELECT * FROM (SELECT a COLLATE nocase, b FROM t6) AS x | 615 4a { SELECT * FROM (SELECT a COLLATE nocase, b FROM t6) AS x |
612 %JOIN% t5 USING (a) } | 616 %JOIN% t5 USING (a) } |
613 {aa cc cc bb DD dd} | 617 {aa cc cc bb DD dd} |
614 4b { SELECT * FROM (SELECT a COLLATE nocase, b FROM t6) AS x | 618 4b { SELECT * FROM (SELECT a COLLATE nocase, b FROM t6) AS x |
615 %JOIN% t5 ON (x.a=t5.a) } | 619 %JOIN% t5 ON (x.a=t5.a) } |
616 {aa cc AA cc bb DD BB dd} | 620 {aa cc AA cc bb DD BB dd} |
617 } { | 621 } { |
618 do_join_test e_select-1.7.$tn $select $res | 622 do_join_test e_select-1.7.$tn $select $res |
619 } | 623 } |
620 | 624 # EVIDENCE-OF: R-42531-52874 If the join-operator is a "LEFT JOIN" or |
621 # EVIDENCE-OF: R-41434-12448 If the join-op is a "LEFT JOIN" or "LEFT | 625 # "LEFT OUTER JOIN", then after the ON or USING filtering clauses have |
622 # OUTER JOIN", then after the ON or USING filtering clauses have been | 626 # been applied, an extra row is added to the output for each row in the |
623 # applied, an extra row is added to the output for each row in the | |
624 # original left-hand input dataset that corresponds to no rows at all in | 627 # original left-hand input dataset that corresponds to no rows at all in |
625 # the composite dataset (if any). | 628 # the composite dataset (if any). |
626 # | 629 # |
627 do_execsql_test e_select-1.8.0 { | 630 do_execsql_test e_select-1.8.0 { |
628 CREATE TABLE t7(a, b, c); | 631 CREATE TABLE t7(a, b, c); |
629 CREATE TABLE t8(a, d, e); | 632 CREATE TABLE t8(a, d, e); |
630 | 633 |
631 INSERT INTO t7 VALUES('x', 'ex', 24); | 634 INSERT INTO t7 VALUES('x', 'ex', 24); |
632 INSERT INTO t7 VALUES('y', 'why', 25); | 635 INSERT INTO t7 VALUES('y', 'why', 25); |
633 | 636 |
(...skipping 14 matching lines...) Expand all Loading... |
648 # input dataset. | 651 # input dataset. |
649 # | 652 # |
650 do_select_tests e_select-1.9 { | 653 do_select_tests e_select-1.9 { |
651 1a "SELECT * FROM t7 JOIN t8 ON (t7.a=t8.a)" {x ex 24 x abc 24} | 654 1a "SELECT * FROM t7 JOIN t8 ON (t7.a=t8.a)" {x ex 24 x abc 24} |
652 1b "SELECT * FROM t7 LEFT JOIN t8 ON (t7.a=t8.a)" | 655 1b "SELECT * FROM t7 LEFT JOIN t8 ON (t7.a=t8.a)" |
653 {x ex 24 x abc 24 y why 25 {} {} {}} | 656 {x ex 24 x abc 24 y why 25 {} {} {}} |
654 2a "SELECT * FROM t7 JOIN t8 USING (a)" {x ex 24 abc 24} | 657 2a "SELECT * FROM t7 JOIN t8 USING (a)" {x ex 24 abc 24} |
655 2b "SELECT * FROM t7 LEFT JOIN t8 USING (a)" {x ex 24 abc 24 y why 25 {} {}} | 658 2b "SELECT * FROM t7 LEFT JOIN t8 USING (a)" {x ex 24 abc 24 y why 25 {} {}} |
656 } | 659 } |
657 | 660 |
658 # EVIDENCE-OF: R-01809-52134 If the NATURAL keyword is added to any of | 661 # EVIDENCE-OF: R-04932-55942 If the NATURAL keyword is in the |
659 # the join-ops, then an implicit USING clause is added to the | 662 # join-operator then an implicit USING clause is added to the |
660 # join-constraints. The implicit USING clause contains each of the | 663 # join-constraints. The implicit USING clause contains each of the |
661 # column names that appear in both the left and right-hand input | 664 # column names that appear in both the left and right-hand input |
662 # datasets. | 665 # datasets. |
663 # | 666 # |
664 do_select_tests e_select-1-10 { | 667 do_select_tests e_select-1-10 { |
665 1a "SELECT * FROM t7 JOIN t8 USING (a)" {x ex 24 abc 24} | 668 1a "SELECT * FROM t7 JOIN t8 USING (a)" {x ex 24 abc 24} |
666 1b "SELECT * FROM t7 NATURAL JOIN t8" {x ex 24 abc 24} | 669 1b "SELECT * FROM t7 NATURAL JOIN t8" {x ex 24 abc 24} |
667 | 670 |
668 2a "SELECT * FROM t8 JOIN t7 USING (a)" {x abc 24 ex 24} | 671 2a "SELECT * FROM t8 JOIN t7 USING (a)" {x abc 24 ex 24} |
669 2b "SELECT * FROM t8 NATURAL JOIN t7" {x abc 24 ex 24} | 672 2b "SELECT * FROM t8 NATURAL JOIN t7" {x abc 24 ex 24} |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
722 INSERT INTO x1 VALUES(5, NULL, 96.28, NULL); | 725 INSERT INTO x1 VALUES(5, NULL, 96.28, NULL); |
723 INSERT INTO x1 VALUES(6, 0, 1, 2); | 726 INSERT INTO x1 VALUES(6, 0, 1, 2); |
724 | 727 |
725 CREATE TABLE x2(k, x, y2); | 728 CREATE TABLE x2(k, x, y2); |
726 INSERT INTO x2 VALUES(1, 50, X'B82838'); | 729 INSERT INTO x2 VALUES(1, 50, X'B82838'); |
727 INSERT INTO x2 VALUES(5, 84.79, 65.88); | 730 INSERT INTO x2 VALUES(5, 84.79, 65.88); |
728 INSERT INTO x2 VALUES(3, -22, X'0E1BE452A393'); | 731 INSERT INTO x2 VALUES(3, -22, X'0E1BE452A393'); |
729 INSERT INTO x2 VALUES(7, 'mistrusted', 'standardized'); | 732 INSERT INTO x2 VALUES(7, 'mistrusted', 'standardized'); |
730 } {} | 733 } {} |
731 | 734 |
732 # EVIDENCE-OF: R-06999-14330 If a WHERE clause is specified, the WHERE | 735 # EVIDENCE-OF: R-60775-64916 If a WHERE clause is specified, the WHERE |
733 # expression is evaluated for each row in the input data as a boolean | 736 # expression is evaluated for each row in the input data as a boolean |
734 # expression. All rows for which the WHERE clause expression evaluates | 737 # expression. Only rows for which the WHERE clause expression evaluates |
735 # to false are excluded from the dataset before continuing. | 738 # to true are included from the dataset before continuing. |
736 # | 739 # |
737 do_execsql_test e_select-3.1.1 { SELECT k FROM x1 WHERE x } {3} | 740 do_execsql_test e_select-3.1.1 { SELECT k FROM x1 WHERE x } {3} |
738 do_execsql_test e_select-3.1.2 { SELECT k FROM x1 WHERE y } {3 5 6} | 741 do_execsql_test e_select-3.1.2 { SELECT k FROM x1 WHERE y } {3 5 6} |
739 do_execsql_test e_select-3.1.3 { SELECT k FROM x1 WHERE z } {1 2 6} | 742 do_execsql_test e_select-3.1.3 { SELECT k FROM x1 WHERE z } {1 2 6} |
740 do_execsql_test e_select-3.1.4 { SELECT k FROM x1 WHERE '1'||z } {1 2 4 6} | 743 do_execsql_test e_select-3.1.4 { SELECT k FROM x1 WHERE '1'||z } {1 2 4 6} |
741 do_execsql_test e_select-3.1.5 { SELECT k FROM x1 WHERE x IS NULL } {4 5} | 744 do_execsql_test e_select-3.1.5 { SELECT k FROM x1 WHERE x IS NULL } {4 5} |
742 do_execsql_test e_select-3.1.6 { SELECT k FROM x1 WHERE z - 78.43 } {2 4 6} | 745 do_execsql_test e_select-3.1.6 { SELECT k FROM x1 WHERE z - 78.43 } {2 4 6} |
743 | 746 |
744 do_execsql_test e_select-3.2.1a { | 747 do_execsql_test e_select-3.2.1a { |
745 SELECT k FROM x1 LEFT JOIN x2 USING(k) | 748 SELECT k FROM x1 LEFT JOIN x2 USING(k) |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
793 # | 796 # |
794 do_select_tests e_select-4.1 { | 797 do_select_tests e_select-4.1 { |
795 1 "SELECT * FROM z1 LIMIT 1" {51.65 -59.58 belfries} | 798 1 "SELECT * FROM z1 LIMIT 1" {51.65 -59.58 belfries} |
796 2 "SELECT * FROM z1,z2 LIMIT 1" {51.65 -59.58 belfries {} 21} | 799 2 "SELECT * FROM z1,z2 LIMIT 1" {51.65 -59.58 belfries {} 21} |
797 3 "SELECT z1.* FROM z1,z2 LIMIT 1" {51.65 -59.58 belfries} | 800 3 "SELECT z1.* FROM z1,z2 LIMIT 1" {51.65 -59.58 belfries} |
798 4 "SELECT z2.* FROM z1,z2 LIMIT 1" {{} 21} | 801 4 "SELECT z2.* FROM z1,z2 LIMIT 1" {{} 21} |
799 5 "SELECT z2.*, z1.* FROM z1,z2 LIMIT 1" {{} 21 51.65 -59.58 belfries} | 802 5 "SELECT z2.*, z1.* FROM z1,z2 LIMIT 1" {{} 21 51.65 -59.58 belfries} |
800 | 803 |
801 6 "SELECT count(*), * FROM z1" {6 63 born -26} | 804 6 "SELECT count(*), * FROM z1" {6 63 born -26} |
802 7 "SELECT max(a), * FROM z1" {63 63 born -26} | 805 7 "SELECT max(a), * FROM z1" {63 63 born -26} |
803 8 "SELECT *, min(a) FROM z1" {63 born -26 -5} | 806 8 "SELECT *, min(a) FROM z1" {-5 {} 75 -5} |
804 | 807 |
805 9 "SELECT *,* FROM z1,z2 LIMIT 1" { | 808 9 "SELECT *,* FROM z1,z2 LIMIT 1" { |
806 51.65 -59.58 belfries {} 21 51.65 -59.58 belfries {} 21 | 809 51.65 -59.58 belfries {} 21 51.65 -59.58 belfries {} 21 |
807 } | 810 } |
808 10 "SELECT z1.*,z1.* FROM z2,z1 LIMIT 1" { | 811 10 "SELECT z1.*,z1.* FROM z2,z1 LIMIT 1" { |
809 51.65 -59.58 belfries 51.65 -59.58 belfries | 812 51.65 -59.58 belfries 51.65 -59.58 belfries |
810 } | 813 } |
811 } | 814 } |
812 | 815 |
813 # EVIDENCE-OF: R-61869-22578 It is an error to use a "*" or "alias.*" | 816 # EVIDENCE-OF: R-38023-18396 It is an error to use a "*" or "alias.*" |
814 # expression in any context other than than a result expression list. | 817 # expression in any context other than a result expression list. |
815 # | 818 # |
816 # EVIDENCE-OF: R-44324-41166 It is also an error to use a "*" or | 819 # EVIDENCE-OF: R-44324-41166 It is also an error to use a "*" or |
817 # "alias.*" expression in a simple SELECT query that does not have a | 820 # "alias.*" expression in a simple SELECT query that does not have a |
818 # FROM clause. | 821 # FROM clause. |
819 # | 822 # |
820 foreach {tn select err} { | 823 foreach {tn select err} { |
821 1.1 "SELECT a, b, c FROM z1 WHERE *" {near "*": syntax error} | 824 1.1 "SELECT a, b, c FROM z1 WHERE *" {near "*": syntax error} |
822 1.2 "SELECT a, b, c FROM z1 GROUP BY *" {near "*": syntax error} | 825 1.2 "SELECT a, b, c FROM z1 GROUP BY *" {near "*": syntax error} |
823 1.3 "SELECT 1 + * FROM z1" {near "*": syntax error} | 826 1.3 "SELECT 1 + * FROM z1" {near "*": syntax error} |
824 1.4 "SELECT * + 1 FROM z1" {near "+": syntax error} | 827 1.4 "SELECT * + 1 FROM z1" {near "+": syntax error} |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
997 INSERT INTO b2 VALUES('abc', 3); | 1000 INSERT INTO b2 VALUES('abc', 3); |
998 INSERT INTO b2 VALUES('xyz', 4); | 1001 INSERT INTO b2 VALUES('xyz', 4); |
999 | 1002 |
1000 CREATE TABLE b3(a COLLATE nocase, b COLLATE binary); | 1003 CREATE TABLE b3(a COLLATE nocase, b COLLATE binary); |
1001 INSERT INTO b3 VALUES('abc', 'abc'); | 1004 INSERT INTO b3 VALUES('abc', 'abc'); |
1002 INSERT INTO b3 VALUES('aBC', 'aBC'); | 1005 INSERT INTO b3 VALUES('aBC', 'aBC'); |
1003 INSERT INTO b3 VALUES('Def', 'Def'); | 1006 INSERT INTO b3 VALUES('Def', 'Def'); |
1004 INSERT INTO b3 VALUES('dEF', 'dEF'); | 1007 INSERT INTO b3 VALUES('dEF', 'dEF'); |
1005 } {} | 1008 } {} |
1006 | 1009 |
1007 # EVIDENCE-OF: R-57754-57109 If the SELECT statement is an aggregate | 1010 # EVIDENCE-OF: R-07284-35990 If the SELECT statement is an aggregate |
1008 # query with a GROUP BY clause, then each of the expressions specified | 1011 # query with a GROUP BY clause, then each of the expressions specified |
1009 # as part of the GROUP BY clause is evaluated for each row of the | 1012 # as part of the GROUP BY clause is evaluated for each row of the |
1010 # dataset. Each row is then assigned to a "group" based on the results; | 1013 # dataset. Each row is then assigned to a "group" based on the results; |
1011 # rows for which the results of evaluating the GROUP BY expressions are | 1014 # rows for which the results of evaluating the GROUP BY expressions are |
1012 # the same are assigned to the same group. | 1015 # the same get assigned to the same group. |
1013 # | 1016 # |
1014 # These tests also show that the following is not untrue: | 1017 # These tests also show that the following is not untrue: |
1015 # | 1018 # |
1016 # EVIDENCE-OF: R-25883-55063 The expressions in the GROUP BY clause do | 1019 # EVIDENCE-OF: R-25883-55063 The expressions in the GROUP BY clause do |
1017 # not have to be expressions that appear in the result. | 1020 # not have to be expressions that appear in the result. |
1018 # | 1021 # |
1019 do_select_tests e_select-4.9 { | 1022 do_select_tests e_select-4.9 { |
1020 1 "SELECT group_concat(one), two FROM b1 GROUP BY two" { | 1023 1 "SELECT group_concat(one), two FROM b1 GROUP BY two" { |
1021 4,5 f 1 o 7,6 s 3,2 t | 1024 /#,# f 1 o #,# s #,# t/ |
1022 } | 1025 } |
1023 2 "SELECT group_concat(one), sum(one) FROM b1 GROUP BY (one>4)" { | 1026 2 "SELECT group_concat(one), sum(one) FROM b1 GROUP BY (one>4)" { |
1024 1,4,3,2 10 5,7,6 18 | 1027 1,2,3,4 10 5,6,7 18 |
1025 } | 1028 } |
1026 3 "SELECT group_concat(one) FROM b1 GROUP BY (two>'o'), one%2" { | 1029 3 "SELECT group_concat(one) FROM b1 GROUP BY (two>'o'), one%2" { |
1027 4 1,5 2,6 3,7 | 1030 4 1,5 2,6 3,7 |
1028 } | 1031 } |
1029 4 "SELECT group_concat(one) FROM b1 GROUP BY (one==2 OR two=='o')" { | 1032 4 "SELECT group_concat(one) FROM b1 GROUP BY (one==2 OR two=='o')" { |
1030 4,3,5,7,6 1,2 | 1033 4,3,5,7,6 1,2 |
1031 } | 1034 } |
1032 } | 1035 } |
1033 | 1036 |
1034 # EVIDENCE-OF: R-14926-50129 For the purposes of grouping rows, NULL | 1037 # EVIDENCE-OF: R-14926-50129 For the purposes of grouping rows, NULL |
1035 # values are considered equal. | 1038 # values are considered equal. |
1036 # | 1039 # |
1037 do_select_tests e_select-4.10 { | 1040 do_select_tests e_select-4.10 { |
1038 1 "SELECT group_concat(y) FROM b2 GROUP BY x" {0,1 3 2,4} | 1041 1 "SELECT group_concat(y) FROM b2 GROUP BY x" {/#,# 3 #,#/} |
1039 2 "SELECT count(*) FROM b2 GROUP BY CASE WHEN y<4 THEN NULL ELSE 0 END" {4 1} | 1042 2 "SELECT count(*) FROM b2 GROUP BY CASE WHEN y<4 THEN NULL ELSE 0 END" {4 1} |
1040 } | 1043 } |
1041 | 1044 |
1042 # EVIDENCE-OF: R-10470-30318 The usual rules for selecting a collation | 1045 # EVIDENCE-OF: R-10470-30318 The usual rules for selecting a collation |
1043 # sequence with which to compare text values apply when evaluating | 1046 # sequence with which to compare text values apply when evaluating |
1044 # expressions in a GROUP BY clause. | 1047 # expressions in a GROUP BY clause. |
1045 # | 1048 # |
1046 do_select_tests e_select-4.11 { | 1049 do_select_tests e_select-4.11 { |
1047 1 "SELECT count(*) FROM b3 GROUP BY b" {1 1 1 1} | 1050 1 "SELECT count(*) FROM b3 GROUP BY b" {1 1 1 1} |
1048 2 "SELECT count(*) FROM b3 GROUP BY a" {2 2} | 1051 2 "SELECT count(*) FROM b3 GROUP BY a" {2 2} |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1214 # follow the SELECT keyword in a simple SELECT statement. | 1217 # follow the SELECT keyword in a simple SELECT statement. |
1215 # | 1218 # |
1216 do_select_tests e_select-5.1 { | 1219 do_select_tests e_select-5.1 { |
1217 1 "SELECT ALL a FROM h1" {1 1 1 4 4 4} | 1220 1 "SELECT ALL a FROM h1" {1 1 1 4 4 4} |
1218 2 "SELECT DISTINCT a FROM h1" {1 4} | 1221 2 "SELECT DISTINCT a FROM h1" {1 4} |
1219 } | 1222 } |
1220 | 1223 |
1221 # EVIDENCE-OF: R-08861-34280 If the simple SELECT is a SELECT ALL, then | 1224 # EVIDENCE-OF: R-08861-34280 If the simple SELECT is a SELECT ALL, then |
1222 # the entire set of result rows are returned by the SELECT. | 1225 # the entire set of result rows are returned by the SELECT. |
1223 # | 1226 # |
1224 # EVIDENCE-OF: R-47911-02086 If neither ALL or DISTINCT are present, | 1227 # EVIDENCE-OF: R-01256-01950 If neither ALL or DISTINCT are present, |
1225 # then the behaviour is as if ALL were specified. | 1228 # then the behavior is as if ALL were specified. |
1226 # | 1229 # |
1227 # EVIDENCE-OF: R-14442-41305 If the simple SELECT is a SELECT DISTINCT, | 1230 # EVIDENCE-OF: R-14442-41305 If the simple SELECT is a SELECT DISTINCT, |
1228 # then duplicate rows are removed from the set of result rows before it | 1231 # then duplicate rows are removed from the set of result rows before it |
1229 # is returned. | 1232 # is returned. |
1230 # | 1233 # |
1231 # The three testable statements above are tested by e_select-5.2.*, | 1234 # The three testable statements above are tested by e_select-5.2.*, |
1232 # 5.3.* and 5.4.* respectively. | 1235 # 5.3.* and 5.4.* respectively. |
1233 # | 1236 # |
1234 do_select_tests e_select-5 { | 1237 do_select_tests e_select-5 { |
1235 3.1 "SELECT ALL x FROM h2" {One Two Three Four one two three four} | 1238 3.1 "SELECT ALL x FROM h2" {One Two Three Four one two three four} |
1236 3.2 "SELECT ALL x FROM h1, h2 ON (x=b)" {One one Four four} | 1239 3.2 "SELECT ALL x FROM h1, h2 ON (x=b)" {One one Four four} |
1237 | 1240 |
1238 3.1 "SELECT x FROM h2" {One Two Three Four one two three four} | 1241 3.1 "SELECT x FROM h2" {One Two Three Four one two three four} |
1239 3.2 "SELECT x FROM h1, h2 ON (x=b)" {One one Four four} | 1242 3.2 "SELECT x FROM h1, h2 ON (x=b)" {One one Four four} |
1240 | 1243 |
1241 4.1 "SELECT DISTINCT x FROM h2" {four one three two} | 1244 4.1 "SELECT DISTINCT x FROM h2" {One Two Three Four} |
1242 4.2 "SELECT DISTINCT x FROM h1, h2 ON (x=b)" {four one} | 1245 4.2 "SELECT DISTINCT x FROM h1, h2 ON (x=b)" {One Four} |
1243 } | 1246 } |
1244 | 1247 |
1245 # EVIDENCE-OF: R-02054-15343 For the purposes of detecting duplicate | 1248 # EVIDENCE-OF: R-02054-15343 For the purposes of detecting duplicate |
1246 # rows, two NULL values are considered to be equal. | 1249 # rows, two NULL values are considered to be equal. |
1247 # | 1250 # |
1248 do_select_tests e_select-5.5 { | 1251 do_select_tests e_select-5.5 { |
1249 1 "SELECT DISTINCT d FROM h3" {{} 2 2,3 2,4 3} | 1252 1 "SELECT DISTINCT d FROM h3" {{} 2 2,3 2,4 3} |
1250 } | 1253 } |
1251 | 1254 |
1252 # EVIDENCE-OF: R-58359-52112 The normal rules for selecting a collation | 1255 # EVIDENCE-OF: R-58359-52112 The normal rules for selecting a collation |
1253 # sequence to compare text values with apply. | 1256 # sequence to compare text values with apply. |
1254 # | 1257 # |
1255 do_select_tests e_select-5.6 { | 1258 do_select_tests e_select-5.6 { |
1256 1 "SELECT DISTINCT b FROM h1" {I IV four i iv one} | 1259 1 "SELECT DISTINCT b FROM h1" {one I i four IV iv} |
1257 2 "SELECT DISTINCT b COLLATE nocase FROM h1" {four i iv one} | 1260 2 "SELECT DISTINCT b COLLATE nocase FROM h1" {one I four IV} |
1258 3 "SELECT DISTINCT x FROM h2" {four one three two} | 1261 3 "SELECT DISTINCT x FROM h2" {One Two Three Four} |
1259 4 "SELECT DISTINCT x COLLATE binary FROM h2" { | 1262 4 "SELECT DISTINCT x COLLATE binary FROM h2" { |
1260 Four One Three Two four one three two | 1263 One Two Three Four one two three four |
1261 } | 1264 } |
1262 } | 1265 } |
1263 | 1266 |
1264 #------------------------------------------------------------------------- | 1267 #------------------------------------------------------------------------- |
1265 # The following tests - e_select-7.* - test that statements made to do | 1268 # The following tests - e_select-7.* - test that statements made to do |
1266 # with compound SELECT statements are correct. | 1269 # with compound SELECT statements are correct. |
1267 # | 1270 # |
1268 | 1271 |
1269 # EVIDENCE-OF: R-39368-64333 In a compound SELECT, all the constituent | 1272 # EVIDENCE-OF: R-39368-64333 In a compound SELECT, all the constituent |
1270 # SELECTs must return the same number of result columns. | 1273 # SELECTs must return the same number of result columns. |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1361 LIMIT {INTERSECT} | 1364 LIMIT {INTERSECT} |
1362 23 "SELECT * FROM j1 LIMIT 10 OFFSET 5 INTERSECT SELECT * FROM j2,j3" | 1365 23 "SELECT * FROM j1 LIMIT 10 OFFSET 5 INTERSECT SELECT * FROM j2,j3" |
1363 LIMIT {INTERSECT} | 1366 LIMIT {INTERSECT} |
1364 24 "SELECT a FROM j1 LIMIT (SELECT e FROM j2) INTERSECT SELECT g FROM j2,j3" | 1367 24 "SELECT a FROM j1 LIMIT (SELECT e FROM j2) INTERSECT SELECT g FROM j2,j3" |
1365 LIMIT {INTERSECT} | 1368 LIMIT {INTERSECT} |
1366 } { | 1369 } { |
1367 set err "$op1 clause should come after $op2 not before" | 1370 set err "$op1 clause should come after $op2 not before" |
1368 do_catchsql_test e_select-7.2.$tn $select [list 1 $err] | 1371 do_catchsql_test e_select-7.2.$tn $select [list 1 $err] |
1369 } | 1372 } |
1370 | 1373 |
1371 # EVIDENCE-OF: R-22874-32655 ORDER BY and LIMIT clauses may only occur | 1374 # EVIDENCE-OF: R-45440-25633 ORDER BY and LIMIT clauses may only occur |
1372 # at the end of the entire compound SELECT. | 1375 # at the end of the entire compound SELECT, and then only if the final |
| 1376 # element of the compound is not a VALUES clause. |
1373 # | 1377 # |
1374 foreach {tn select} { | 1378 foreach {tn select} { |
1375 1 "SELECT * FROM j1 UNION ALL SELECT * FROM j2,j3 ORDER BY a" | 1379 1 "SELECT * FROM j1 UNION ALL SELECT * FROM j2,j3 ORDER BY a" |
1376 2 "SELECT count(*) FROM j1 UNION ALL SELECT max(e) FROM j2 ORDER BY 1" | 1380 2 "SELECT count(*) FROM j1 UNION ALL SELECT max(e) FROM j2 ORDER BY 1" |
1377 3 "SELECT count(*), * FROM j1 UNION ALL SELECT *,* FROM j2 ORDER BY 1,2,3" | 1381 3 "SELECT count(*), * FROM j1 UNION ALL SELECT *,* FROM j2 ORDER BY 1,2,3" |
1378 4 "SELECT * FROM j1 UNION ALL SELECT * FROM j2,j3 LIMIT 10" | 1382 4 "SELECT * FROM j1 UNION ALL SELECT * FROM j2,j3 LIMIT 10" |
1379 5 "SELECT * FROM j1 UNION ALL SELECT * FROM j2,j3 LIMIT 10 OFFSET 5" | 1383 5 "SELECT * FROM j1 UNION ALL SELECT * FROM j2,j3 LIMIT 10 OFFSET 5" |
1380 6 "SELECT a FROM j1 UNION ALL SELECT g FROM j2,j3 LIMIT (SELECT 10)" | 1384 6 "SELECT a FROM j1 UNION ALL SELECT g FROM j2,j3 LIMIT (SELECT 10)" |
1381 | 1385 |
1382 7 "SELECT * FROM j1 UNION SELECT * FROM j2,j3 ORDER BY a" | 1386 7 "SELECT * FROM j1 UNION SELECT * FROM j2,j3 ORDER BY a" |
1383 8 "SELECT count(*) FROM j1 UNION SELECT max(e) FROM j2 ORDER BY 1" | 1387 8 "SELECT count(*) FROM j1 UNION SELECT max(e) FROM j2 ORDER BY 1" |
| 1388 8b "VALUES('8b') UNION SELECT max(e) FROM j2 ORDER BY 1" |
1384 9 "SELECT count(*), * FROM j1 UNION SELECT *,* FROM j2 ORDER BY 1,2,3" | 1389 9 "SELECT count(*), * FROM j1 UNION SELECT *,* FROM j2 ORDER BY 1,2,3" |
1385 10 "SELECT * FROM j1 UNION SELECT * FROM j2,j3 LIMIT 10" | 1390 10 "SELECT * FROM j1 UNION SELECT * FROM j2,j3 LIMIT 10" |
1386 11 "SELECT * FROM j1 UNION SELECT * FROM j2,j3 LIMIT 10 OFFSET 5" | 1391 11 "SELECT * FROM j1 UNION SELECT * FROM j2,j3 LIMIT 10 OFFSET 5" |
1387 12 "SELECT a FROM j1 UNION SELECT g FROM j2,j3 LIMIT (SELECT 10)" | 1392 12 "SELECT a FROM j1 UNION SELECT g FROM j2,j3 LIMIT (SELECT 10)" |
1388 | 1393 |
1389 13 "SELECT * FROM j1 EXCEPT SELECT * FROM j2,j3 ORDER BY a" | 1394 13 "SELECT * FROM j1 EXCEPT SELECT * FROM j2,j3 ORDER BY a" |
1390 14 "SELECT count(*) FROM j1 EXCEPT SELECT max(e) FROM j2 ORDER BY 1" | 1395 14 "SELECT count(*) FROM j1 EXCEPT SELECT max(e) FROM j2 ORDER BY 1" |
1391 15 "SELECT count(*), * FROM j1 EXCEPT SELECT *,* FROM j2 ORDER BY 1,2,3" | 1396 15 "SELECT count(*), * FROM j1 EXCEPT SELECT *,* FROM j2 ORDER BY 1,2,3" |
1392 16 "SELECT * FROM j1 EXCEPT SELECT * FROM j2,j3 LIMIT 10" | 1397 16 "SELECT * FROM j1 EXCEPT SELECT * FROM j2,j3 LIMIT 10" |
1393 17 "SELECT * FROM j1 EXCEPT SELECT * FROM j2,j3 LIMIT 10 OFFSET 5" | 1398 17 "SELECT * FROM j1 EXCEPT SELECT * FROM j2,j3 LIMIT 10 OFFSET 5" |
1394 18 "SELECT a FROM j1 EXCEPT SELECT g FROM j2,j3 LIMIT (SELECT 10)" | 1399 18 "SELECT a FROM j1 EXCEPT SELECT g FROM j2,j3 LIMIT (SELECT 10)" |
1395 | 1400 |
1396 19 "SELECT * FROM j1 INTERSECT SELECT * FROM j2,j3 ORDER BY a" | 1401 19 "SELECT * FROM j1 INTERSECT SELECT * FROM j2,j3 ORDER BY a" |
1397 20 "SELECT count(*) FROM j1 INTERSECT SELECT max(e) FROM j2 ORDER BY 1" | 1402 20 "SELECT count(*) FROM j1 INTERSECT SELECT max(e) FROM j2 ORDER BY 1" |
1398 21 "SELECT count(*), * FROM j1 INTERSECT SELECT *,* FROM j2 ORDER BY 1,2,3" | 1403 21 "SELECT count(*), * FROM j1 INTERSECT SELECT *,* FROM j2 ORDER BY 1,2,3" |
1399 22 "SELECT * FROM j1 INTERSECT SELECT * FROM j2,j3 LIMIT 10" | 1404 22 "SELECT * FROM j1 INTERSECT SELECT * FROM j2,j3 LIMIT 10" |
1400 23 "SELECT * FROM j1 INTERSECT SELECT * FROM j2,j3 LIMIT 10 OFFSET 5" | 1405 23 "SELECT * FROM j1 INTERSECT SELECT * FROM j2,j3 LIMIT 10 OFFSET 5" |
1401 24 "SELECT a FROM j1 INTERSECT SELECT g FROM j2,j3 LIMIT (SELECT 10)" | 1406 24 "SELECT a FROM j1 INTERSECT SELECT g FROM j2,j3 LIMIT (SELECT 10)" |
1402 } { | 1407 } { |
1403 do_test e_select-7.3.$tn { catch {execsql $select} msg } 0 | 1408 do_test e_select-7.3.$tn { catch {execsql $select} msg } 0 |
1404 } | 1409 } |
| 1410 foreach {tn select} { |
| 1411 50 "SELECT * FROM j1 ORDER BY 1 UNION ALL SELECT * FROM j2,j3" |
| 1412 51 "SELECT * FROM j1 LIMIT 1 UNION ALL SELECT * FROM j2,j3" |
| 1413 52 "SELECT count(*) FROM j1 UNION ALL VALUES(11) ORDER BY 1" |
| 1414 53 "SELECT count(*) FROM j1 UNION ALL VALUES(11) LIMIT 1" |
| 1415 } { |
| 1416 do_test e_select-7.3.$tn { catch {execsql $select} msg } 1 |
| 1417 } |
1405 | 1418 |
1406 # EVIDENCE-OF: R-08531-36543 A compound SELECT created using UNION ALL | 1419 # EVIDENCE-OF: R-08531-36543 A compound SELECT created using UNION ALL |
1407 # operator returns all the rows from the SELECT to the left of the UNION | 1420 # operator returns all the rows from the SELECT to the left of the UNION |
1408 # ALL operator, and all the rows from the SELECT to the right of it. | 1421 # ALL operator, and all the rows from the SELECT to the right of it. |
1409 # | 1422 # |
1410 drop_all_tables | 1423 drop_all_tables |
1411 do_execsql_test e_select-7.4.0 { | 1424 do_execsql_test e_select-7.4.0 { |
1412 CREATE TABLE q1(a TEXT, b INTEGER, c); | 1425 CREATE TABLE q1(a TEXT, b INTEGER, c); |
1413 CREATE TABLE q2(d NUMBER, e BLOB); | 1426 CREATE TABLE q2(d NUMBER, e BLOB); |
1414 CREATE TABLE q3(f REAL, g); | 1427 CREATE TABLE q3(f REAL, g); |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1733 } | 1746 } |
1734 6 "SELECT * FROM d1 ORDER BY 1 DESC, 2, 3 DESC" { | 1747 6 "SELECT * FROM d1 ORDER BY 1 DESC, 2, 3 DESC" { |
1735 2 4 93 2 5 -1 1 2 8 1 2 7 | 1748 2 4 93 2 5 -1 1 2 8 1 2 7 |
1736 1 2 3 1 2 -20 1 4 93 1 5 -1 | 1749 1 2 3 1 2 -20 1 4 93 1 5 -1 |
1737 } | 1750 } |
1738 7 "SELECT * FROM d1 ORDER BY 1 DESC, 2, 3" { | 1751 7 "SELECT * FROM d1 ORDER BY 1 DESC, 2, 3" { |
1739 2 4 93 2 5 -1 1 2 -20 1 2 3 | 1752 2 4 93 2 5 -1 1 2 -20 1 2 3 |
1740 1 2 7 1 2 8 1 4 93 1 5 -1 | 1753 1 2 7 1 2 8 1 4 93 1 5 -1 |
1741 } | 1754 } |
1742 8 "SELECT z, x FROM d1 ORDER BY 2" { | 1755 8 "SELECT z, x FROM d1 ORDER BY 2" { |
1743 3 1 8 1 7 1 -20 1 | 1756 /# 1 # 1 # 1 # 1 |
1744 93 1 -1 1 -1 2 93 2 | 1757 # 1 # 1 # 2 # 2/ |
1745 } | 1758 } |
1746 9 "SELECT z, x FROM d1 ORDER BY 1" { | 1759 9 "SELECT z, x FROM d1 ORDER BY 1" { |
1747 -20 1 -1 2 -1 1 3 1 | 1760 /-20 1 -1 # -1 # 3 1 |
1748 7 1 8 1 93 2 93 1 | 1761 7 1 8 1 93 # 93 #/ |
1749 } | 1762 } |
1750 } | 1763 } |
1751 | 1764 |
1752 # EVIDENCE-OF: R-63286-51977 If the ORDER BY expression is an identifier | 1765 # EVIDENCE-OF: R-63286-51977 If the ORDER BY expression is an identifier |
1753 # that corresponds to the alias of one of the output columns, then the | 1766 # that corresponds to the alias of one of the output columns, then the |
1754 # expression is considered an alias for that column. | 1767 # expression is considered an alias for that column. |
1755 # | 1768 # |
1756 do_select_tests e_select-8.5 { | 1769 do_select_tests e_select-8.5 { |
1757 1 "SELECT z+1 AS abc FROM d1 ORDER BY abc" { | 1770 1 "SELECT z+1 AS abc FROM d1 ORDER BY abc" { |
1758 -19 0 0 4 8 9 94 94 | 1771 -19 0 0 4 8 9 94 94 |
1759 } | 1772 } |
1760 2 "SELECT z+1 AS abc FROM d1 ORDER BY abc DESC" { | 1773 2 "SELECT z+1 AS abc FROM d1 ORDER BY abc DESC" { |
1761 94 94 9 8 4 0 0 -19 | 1774 94 94 9 8 4 0 0 -19 |
1762 } | 1775 } |
1763 3 "SELECT z AS x, x AS z FROM d1 ORDER BY z" { | 1776 3 "SELECT z AS x, x AS z FROM d1 ORDER BY z" { |
1764 3 1 8 1 7 1 -20 1 93 1 -1 1 -1 2 93 2 | 1777 /# 1 # 1 # 1 # 1 # 1 # 1 # 2 # 2/ |
1765 } | 1778 } |
1766 4 "SELECT z AS x, x AS z FROM d1 ORDER BY x" { | 1779 4 "SELECT z AS x, x AS z FROM d1 ORDER BY x" { |
1767 -20 1 -1 2 -1 1 3 1 7 1 8 1 93 2 93 1 | 1780 /-20 1 -1 # -1 # 3 1 7 1 8 1 93 # 93 #/ |
1768 } | 1781 } |
1769 } | 1782 } |
1770 | 1783 |
1771 # EVIDENCE-OF: R-27923-38747 Otherwise, if the ORDER BY expression is | 1784 # EVIDENCE-OF: R-65068-27207 Otherwise, if the ORDER BY expression is |
1772 # any other expression, it is evaluated and the the returned value used | 1785 # any other expression, it is evaluated and the returned value used to |
1773 # to order the output rows. | 1786 # order the output rows. |
1774 # | 1787 # |
1775 # EVIDENCE-OF: R-03421-57988 If the SELECT statement is a simple SELECT, | 1788 # EVIDENCE-OF: R-03421-57988 If the SELECT statement is a simple SELECT, |
1776 # then an ORDER BY may contain any arbitrary expressions. | 1789 # then an ORDER BY may contain any arbitrary expressions. |
1777 # | 1790 # |
1778 do_select_tests e_select-8.6 { | 1791 do_select_tests e_select-8.6 { |
1779 1 "SELECT * FROM d1 ORDER BY x+y+z" { | 1792 1 "SELECT * FROM d1 ORDER BY x+y+z" { |
1780 1 2 -20 1 5 -1 1 2 3 2 5 -1 | 1793 1 2 -20 1 5 -1 1 2 3 2 5 -1 |
1781 1 2 7 1 2 8 1 4 93 2 4 93 | 1794 1 2 7 1 2 8 1 4 93 2 4 93 |
1782 } | 1795 } |
1783 2 "SELECT * FROM d1 ORDER BY x*z" { | 1796 2 "SELECT * FROM d1 ORDER BY x*z" { |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2153 | 2166 |
2154 8 { SELECT b FROM f1 ORDER BY a LIMIT 20, 10 } {u v w x y z} | 2167 8 { SELECT b FROM f1 ORDER BY a LIMIT 20, 10 } {u v w x y z} |
2155 9 { SELECT a FROM f1 ORDER BY a DESC LIMIT 18+4, 100 } {4 3 2 1} | 2168 9 { SELECT a FROM f1 ORDER BY a DESC LIMIT 18+4, 100 } {4 3 2 1} |
2156 | 2169 |
2157 10 { SELECT b FROM f1 ORDER BY a LIMIT -1, 5 } {a b c d e} | 2170 10 { SELECT b FROM f1 ORDER BY a LIMIT -1, 5 } {a b c d e} |
2158 11 { SELECT b FROM f1 ORDER BY a LIMIT -500, 5 } {a b c d e} | 2171 11 { SELECT b FROM f1 ORDER BY a LIMIT -500, 5 } {a b c d e} |
2159 12 { SELECT b FROM f1 ORDER BY a LIMIT 0, 5 } {a b c d e} | 2172 12 { SELECT b FROM f1 ORDER BY a LIMIT 0, 5 } {a b c d e} |
2160 } | 2173 } |
2161 | 2174 |
2162 finish_test | 2175 finish_test |
OLD | NEW |