xref: /sqlite-3.40.0/test/joinH.test (revision 7e089d0c)
12a7aff93Sdan# 2022 May 17
22a7aff93Sdan#
32a7aff93Sdan# The author disclaims copyright to this source code.  In place of
42a7aff93Sdan# a legal notice, here is a blessing:
52a7aff93Sdan#
62a7aff93Sdan#    May you do good and not evil.
72a7aff93Sdan#    May you find forgiveness for yourself and forgive others.
82a7aff93Sdan#    May you share freely, never taking more than you give.
92a7aff93Sdan#
102a7aff93Sdan#***********************************************************************
112a7aff93Sdan# This file implements regression tests for SQLite library.
122a7aff93Sdan#
132a7aff93Sdan
142a7aff93Sdanset testdir [file dirname $argv0]
152a7aff93Sdansource $testdir/tester.tcl
162a7aff93Sdanset testprefix joinH
172a7aff93Sdan
182a7aff93Sdando_execsql_test 1.0 {
192a7aff93Sdan  CREATE TABLE t1(a INT);
202a7aff93Sdan  CREATE TABLE t2(b INT);
212a7aff93Sdan  INSERT INTO t2(b) VALUES(NULL);
222a7aff93Sdan}
232a7aff93Sdan
242a7aff93Sdandb nullvalue NULL
252a7aff93Sdan
262a7aff93Sdando_execsql_test 1.1 {
272a7aff93Sdan  SELECT DISTINCT a FROM t1 FULL JOIN t2 ON true WHERE (b ISNULL);
282a7aff93Sdan} {NULL}
292a7aff93Sdando_execsql_test 1.2 {
302a7aff93Sdan  SELECT a FROM t1 FULL JOIN t2 ON true;
312a7aff93Sdan} {NULL}
322a7aff93Sdando_execsql_test 1.3 {
332a7aff93Sdan  SELECT a FROM t1 FULL JOIN t2 ON true WHERE (b ISNULL);
342a7aff93Sdan} {NULL}
352a7aff93Sdando_execsql_test 1.4 {
362a7aff93Sdan  SELECT DISTINCT a FROM t1 FULL JOIN t2 ON true;
372a7aff93Sdan} {NULL}
382a7aff93Sdan
392a7aff93Sdan#-----------------------------------------------------------
402a7aff93Sdan
412a7aff93Sdanreset_db
422a7aff93Sdando_execsql_test 2.0 {
432a7aff93Sdan  CREATE TABLE r3(x);
442a7aff93Sdan  CREATE TABLE r4(y INTEGER PRIMARY KEY);
452a7aff93Sdan  INSERT INTO r4 VALUES(55);
462a7aff93Sdan}
472a7aff93Sdan
482a7aff93Sdando_execsql_test 2.1 {
492a7aff93Sdan  SELECT 'value!' FROM r3 FULL JOIN r4 ON (y=x);
502a7aff93Sdan} {value!}
512a7aff93Sdan
522a7aff93Sdando_execsql_test 2.2 {
532a7aff93Sdan  SELECT 'value!' FROM r3 FULL JOIN r4 ON (y=x) WHERE +y=55;
542a7aff93Sdan} {value!}
552a7aff93Sdan
56a5ec23a7Sdan#-----------------------------------------------------------
57a5ec23a7Sdanreset_db
58a5ec23a7Sdando_execsql_test 3.1 {
59a5ec23a7Sdan  CREATE TABLE t0 (c0);
60a5ec23a7Sdan  CREATE TABLE t1 (c0);
61a5ec23a7Sdan  CREATE TABLE t2 (c0 , c1 , c2 , UNIQUE (c0), UNIQUE (c2 DESC));
62a5ec23a7Sdan  INSERT INTO t2 VALUES ('x', 'y', 'z');
63a5ec23a7Sdan  ANALYZE;
64a5ec23a7Sdan  CREATE VIEW v0(c0) AS SELECT FALSE;
65a5ec23a7Sdan}
66a5ec23a7Sdan
67a5ec23a7Sdando_catchsql_test 3.2 {
68a5ec23a7Sdan  SELECT * FROM t0 LEFT OUTER JOIN t1 ON v0.c0 INNER JOIN v0 INNER JOIN t2 ON (t2.c2 NOT NULL);
69a5ec23a7Sdan} {1 {ON clause references tables to its right}}
70a5ec23a7Sdan
71*7e089d0cSdan#-------------------------------------------------------------
72*7e089d0cSdan
73*7e089d0cSdanreset_db
74*7e089d0cSdando_execsql_test 4.1 {
75*7e089d0cSdan  CREATE TABLE t1(a,b,c,d,e,f,g,h,PRIMARY KEY(a,b,c)) WITHOUT ROWID;
76*7e089d0cSdan  CREATE TABLE t2(i, j);
77*7e089d0cSdan  INSERT INTO t2 VALUES(10, 20);
78*7e089d0cSdan}
79*7e089d0cSdan
80*7e089d0cSdando_execsql_test 4.2 {
81*7e089d0cSdan  SELECT (d IS NULL) FROM t1 RIGHT JOIN t2 ON (j=33);
82*7e089d0cSdan} {1}
83*7e089d0cSdan
84*7e089d0cSdando_execsql_test 4.3 {
85*7e089d0cSdan  CREATE INDEX i1 ON t1( (d IS NULL), d );
86*7e089d0cSdan}
87*7e089d0cSdan
88*7e089d0cSdando_execsql_test 4.4 {
89*7e089d0cSdan  SELECT (d IS NULL) FROM t1 RIGHT JOIN t2 ON (j=33);
90*7e089d0cSdan} {1}
91*7e089d0cSdan
922a7aff93Sdan
932a7aff93Sdanfinish_test
94