3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
6 # May you do good and not evil.
7 # May you find forgiveness for yourself and forgive others.
8 # May you share freely, never taking more than you give.
10 #***********************************************************************
11 # This file implements regression tests for SQLite library.
13 # This file implements tests for RIGHT and FULL OUTER JOINs.
15 set testdir [file dirname $argv0]
16 source $testdir/tester.tcl
20 CREATE TABLE t1(a INT, b INT, c INT, d INT);
21 CREATE TABLE t2(c INT, d INT, e INT, f INT);
22 CREATE TABLE t3(a INT, b INT, e INT, f INT);
23 CREATE TABLE t4(a INT, c INT, d INT, f INT);
24 INSERT INTO t1 VALUES(11,21,31,41),(12,22,32,42),(15,25,35,45),(18,28,38,48);
25 INSERT INTO t2 VALUES(12,22,32,42),(13,23,33,43),(15,25,35,45),(17,27,37,47);
26 INSERT INTO t3 VALUES(14,24,34,44),(15,25,35,45),(16,26,36,46);
27 INSERT INTO t4 VALUES(11,21,31,41),(13,23,33,43),(16,26,36,46),(19,29,39,49);
30 CREATE TABLE t1(a INTEGER PRIMARY KEY, b INT, c INT, d INT);
31 CREATE TABLE t2(c INT, d INTEGER PRIMARY KEY, e INT, f INT);
32 CREATE TABLE t3(a INT, b INT, e INTEGER PRIMARY KEY, f INT);
33 CREATE TABLE t4(a INT, c INT, d INT, f INT PRIMARY KEY) WITHOUT ROWID;
34 INSERT INTO t1 VALUES(11,21,31,41),(12,22,32,42),(15,25,35,45),(18,28,38,48);
35 INSERT INTO t2 VALUES(12,22,32,42),(13,23,33,43),(15,25,35,45),(17,27,37,47);
36 INSERT INTO t3 VALUES(14,24,34,44),(15,25,35,45),(16,26,36,46);
37 INSERT INTO t4 VALUES(11,21,31,41),(13,23,33,43),(16,26,36,46),(19,29,39,49);
40 CREATE TABLE t1a(a INT, b INT, c INT, d INT);
41 CREATE TABLE t2a(c INT, d INT, e INT, f INT);
42 CREATE TABLE t3a(a INT, b INT, e INT, f INT);
43 CREATE TABLE t4a(a INT, c INT, d INT, f INT);
44 INSERT INTO t1a VALUES(11,21,31,41),(12,22,32,42);
45 INSERT INTO t2a VALUES(12,22,32,42),(13,23,33,43);
46 INSERT INTO t3a VALUES(14,24,34,44),(15,25,35,45);
47 INSERT INTO t4a VALUES(11,21,31,41),(13,23,33,43);
48 CREATE TABLE t1b(a INT, b INT, c INT, d INT);
49 CREATE TABLE t2b(c INT, d INT, e INT, f INT);
50 CREATE TABLE t3b(a INT, b INT, e INT, f INT);
51 CREATE TABLE t4b(a INT, c INT, d INT, f INT);
52 INSERT INTO t1b VALUES(15,25,35,45),(18,28,38,48);
53 INSERT INTO t2b VALUES(15,25,35,45),(17,27,37,47);
54 INSERT INTO t3b VALUES(15,25,35,45),(16,26,36,46);
55 INSERT INTO t4b VALUES(16,26,36,46),(19,29,39,49);
56 CREATE VIEW t1 AS SELECT * FROM t1a UNION SELECT * FROM t1b;
57 CREATE VIEW t2 AS SELECT * FROM t2a UNION SELECT * FROM t2b;
58 CREATE VIEW t3 AS SELECT * FROM t3a UNION SELECT * FROM t3b;
59 CREATE VIEW t4 AS SELECT * FROM t4a UNION SELECT * FROM t4b;
64 do_execsql_test joinA-$id.setup $schema {}
67 do_execsql_test joinA-$id.100 {
68 SELECT a,b,c,d,t2.e,f,t3.e
70 INNER JOIN t2 USING(c,d)
71 INNER JOIN t3 USING(a,b,f)
72 INNER JOIN t4 USING(a,c,d,f)
73 ORDER BY 1 nulls first, 3 nulls first;
78 do_execsql_test joinA-$id.110 {
79 SELECT a,b,c,d,t2.e,f,t3.e
81 LEFT JOIN t2 USING(c,d)
82 LEFT JOIN t3 USING(a,b,f)
83 LEFT JOIN t4 USING(a,c,d,f)
84 ORDER BY 1 nulls first, 3 nulls first;
93 do_execsql_test joinA-$id.120 {
94 SELECT a,b,c,d,t2.e,f,t3.e
96 LEFT JOIN t2 USING(c,d)
97 RIGHT JOIN t3 USING(a,b,f)
98 LEFT JOIN t4 USING(a,c,d,f)
99 ORDER BY 1 nulls first, 3 nulls first;
107 do_execsql_test joinA-$id.130 {
108 SELECT a,b,c,d,t2.e,f,t3.e
110 RIGHT JOIN t2 USING(c,d)
111 LEFT JOIN t3 USING(a,b,f)
112 RIGHT JOIN t4 USING(a,c,d,f)
113 ORDER BY 1 nulls first, 3 nulls first;
122 do_execsql_test joinA-$id.140 {
123 SELECT a,b,c,d,t2.e,f,t3.e
125 FULL JOIN t2 USING(c,d)
126 LEFT JOIN t3 USING(a,b,f)
127 RIGHT JOIN t4 USING(a,c,d,f)
128 ORDER BY 1 nulls first, 3 nulls first;
137 do_execsql_test joinA-$id.150 {
138 SELECT a,b,c,d,t2.e,f,t3.e
140 RIGHT JOIN t2 USING(c,d)
141 FULL JOIN t3 USING(a,b,f)
142 RIGHT JOIN t4 USING(a,c,d,f)
143 ORDER BY 1 nulls first, 3 nulls first;
152 do_execsql_test joinA-$id.160 {
153 SELECT a,b,c,d,t2.e,f,t3.e
155 RIGHT JOIN t2 USING(c,d)
156 LEFT JOIN t3 USING(a,b,f)
157 FULL JOIN t4 USING(a,c,d,f)
158 ORDER BY 1 nulls first, 3 nulls first;
171 do_execsql_test joinA-$id.170 {
172 SELECT a,b,c,d,t2.e,f,t3.e
174 LEFT JOIN t2 USING(c,d)
175 RIGHT JOIN t3 USING(a,b,f)
176 FULL JOIN t4 USING(a,c,d,f)
177 ORDER BY 1 nulls first, 3 nulls first;
189 do_execsql_test joinA-$id.200 {
190 SELECT a,b,c,d,t2.e,f,t3.e
192 FULL JOIN t2 USING(c,d)
193 FULL JOIN t3 USING(a,b,f)
194 FULL JOIN t4 USING(a,c,d,f)
195 ORDER BY 1 nulls first, 3 nulls first;
215 do_execsql_test joinA-$id.201 {
216 SELECT a,b,c,d,t2.e,f,t3.e,t1.a
218 FULL JOIN t2 USING(c,d)
219 FULL JOIN t3 USING(a,b,f)
220 FULL JOIN t4 USING(a,c,d,f)
222 ORDER BY 1 nulls first, 3 nulls first;
231 do_execsql_test joinA-$id.202 {
232 SELECT a,b,c,d,t2.e,f,t3.e,t3.a
234 FULL JOIN t2 USING(c,d)
235 FULL JOIN t3 USING(a,b,f)
236 FULL JOIN t4 USING(a,c,d,f)
238 ORDER BY 1 nulls first, 3 nulls first;
246 do_execsql_test joinA-$id.203 {
247 SELECT a,b,c,d,t2.e,f,t3.e,t4.a
249 FULL JOIN t2 USING(c,d)
250 FULL JOIN t3 USING(a,b,f)
251 FULL JOIN t4 USING(a,c,d,f)
253 ORDER BY 1 nulls first, 3 nulls first;
262 do_execsql_test joinA-$id.204 {
263 SELECT a,b,c,d,t2.e,f,t3.e
265 FULL JOIN t2 USING(c,d)
266 FULL JOIN t3 USING(a,b,f)
267 FULL JOIN t4 USING(a,c,d,f)
269 ORDER BY 1 nulls first, 3 nulls first;