xref: /titanic_52/usr/src/lib/libsqlite/test/select1.test (revision c5c4113dfcabb1eed3d4bdf7609de5170027a794)
1*c5c4113dSnw141292
2*c5c4113dSnw141292#pragma ident	"%Z%%M%	%I%	%E% SMI"
3*c5c4113dSnw141292
4*c5c4113dSnw141292# 2001 September 15
5*c5c4113dSnw141292#
6*c5c4113dSnw141292# The author disclaims copyright to this source code.  In place of
7*c5c4113dSnw141292# a legal notice, here is a blessing:
8*c5c4113dSnw141292#
9*c5c4113dSnw141292#    May you do good and not evil.
10*c5c4113dSnw141292#    May you find forgiveness for yourself and forgive others.
11*c5c4113dSnw141292#    May you share freely, never taking more than you give.
12*c5c4113dSnw141292#
13*c5c4113dSnw141292#***********************************************************************
14*c5c4113dSnw141292# This file implements regression tests for SQLite library.  The
15*c5c4113dSnw141292# focus of this file is testing the SELECT statement.
16*c5c4113dSnw141292#
17*c5c4113dSnw141292# $Id: select1.test,v 1.30.2.3 2004/07/20 01:45:49 drh Exp $
18*c5c4113dSnw141292
19*c5c4113dSnw141292set testdir [file dirname $argv0]
20*c5c4113dSnw141292source $testdir/tester.tcl
21*c5c4113dSnw141292
22*c5c4113dSnw141292# Try to select on a non-existant table.
23*c5c4113dSnw141292#
24*c5c4113dSnw141292do_test select1-1.1 {
25*c5c4113dSnw141292  set v [catch {execsql {SELECT * FROM test1}} msg]
26*c5c4113dSnw141292  lappend v $msg
27*c5c4113dSnw141292} {1 {no such table: test1}}
28*c5c4113dSnw141292
29*c5c4113dSnw141292execsql {CREATE TABLE test1(f1 int, f2 int)}
30*c5c4113dSnw141292
31*c5c4113dSnw141292do_test select1-1.2 {
32*c5c4113dSnw141292  set v [catch {execsql {SELECT * FROM test1, test2}} msg]
33*c5c4113dSnw141292  lappend v $msg
34*c5c4113dSnw141292} {1 {no such table: test2}}
35*c5c4113dSnw141292do_test select1-1.3 {
36*c5c4113dSnw141292  set v [catch {execsql {SELECT * FROM test2, test1}} msg]
37*c5c4113dSnw141292  lappend v $msg
38*c5c4113dSnw141292} {1 {no such table: test2}}
39*c5c4113dSnw141292
40*c5c4113dSnw141292execsql {INSERT INTO test1(f1,f2) VALUES(11,22)}
41*c5c4113dSnw141292
42*c5c4113dSnw141292
43*c5c4113dSnw141292# Make sure the columns are extracted correctly.
44*c5c4113dSnw141292#
45*c5c4113dSnw141292do_test select1-1.4 {
46*c5c4113dSnw141292  execsql {SELECT f1 FROM test1}
47*c5c4113dSnw141292} {11}
48*c5c4113dSnw141292do_test select1-1.5 {
49*c5c4113dSnw141292  execsql {SELECT f2 FROM test1}
50*c5c4113dSnw141292} {22}
51*c5c4113dSnw141292do_test select1-1.6 {
52*c5c4113dSnw141292  execsql {SELECT f2, f1 FROM test1}
53*c5c4113dSnw141292} {22 11}
54*c5c4113dSnw141292do_test select1-1.7 {
55*c5c4113dSnw141292  execsql {SELECT f1, f2 FROM test1}
56*c5c4113dSnw141292} {11 22}
57*c5c4113dSnw141292do_test select1-1.8 {
58*c5c4113dSnw141292  execsql {SELECT * FROM test1}
59*c5c4113dSnw141292} {11 22}
60*c5c4113dSnw141292do_test select1-1.8.1 {
61*c5c4113dSnw141292  execsql {SELECT *, * FROM test1}
62*c5c4113dSnw141292} {11 22 11 22}
63*c5c4113dSnw141292do_test select1-1.8.2 {
64*c5c4113dSnw141292  execsql {SELECT *, min(f1,f2), max(f1,f2) FROM test1}
65*c5c4113dSnw141292} {11 22 11 22}
66*c5c4113dSnw141292do_test select1-1.8.3 {
67*c5c4113dSnw141292  execsql {SELECT 'one', *, 'two', * FROM test1}
68*c5c4113dSnw141292} {one 11 22 two 11 22}
69*c5c4113dSnw141292
70*c5c4113dSnw141292execsql {CREATE TABLE test2(r1 real, r2 real)}
71*c5c4113dSnw141292execsql {INSERT INTO test2(r1,r2) VALUES(1.1,2.2)}
72*c5c4113dSnw141292
73*c5c4113dSnw141292do_test select1-1.9 {
74*c5c4113dSnw141292  execsql {SELECT * FROM test1, test2}
75*c5c4113dSnw141292} {11 22 1.1 2.2}
76*c5c4113dSnw141292do_test select1-1.9.1 {
77*c5c4113dSnw141292  execsql {SELECT *, 'hi' FROM test1, test2}
78*c5c4113dSnw141292} {11 22 1.1 2.2 hi}
79*c5c4113dSnw141292do_test select1-1.9.2 {
80*c5c4113dSnw141292  execsql {SELECT 'one', *, 'two', * FROM test1, test2}
81*c5c4113dSnw141292} {one 11 22 1.1 2.2 two 11 22 1.1 2.2}
82*c5c4113dSnw141292do_test select1-1.10 {
83*c5c4113dSnw141292  execsql {SELECT test1.f1, test2.r1 FROM test1, test2}
84*c5c4113dSnw141292} {11 1.1}
85*c5c4113dSnw141292do_test select1-1.11 {
86*c5c4113dSnw141292  execsql {SELECT test1.f1, test2.r1 FROM test2, test1}
87*c5c4113dSnw141292} {11 1.1}
88*c5c4113dSnw141292do_test select1-1.11.1 {
89*c5c4113dSnw141292  execsql {SELECT * FROM test2, test1}
90*c5c4113dSnw141292} {1.1 2.2 11 22}
91*c5c4113dSnw141292do_test select1-1.11.2 {
92*c5c4113dSnw141292  execsql {SELECT * FROM test1 AS a, test1 AS b}
93*c5c4113dSnw141292} {11 22 11 22}
94*c5c4113dSnw141292do_test select1-1.12 {
95*c5c4113dSnw141292  execsql {SELECT max(test1.f1,test2.r1), min(test1.f2,test2.r2)
96*c5c4113dSnw141292           FROM test2, test1}
97*c5c4113dSnw141292} {11 2.2}
98*c5c4113dSnw141292do_test select1-1.13 {
99*c5c4113dSnw141292  execsql {SELECT min(test1.f1,test2.r1), max(test1.f2,test2.r2)
100*c5c4113dSnw141292           FROM test1, test2}
101*c5c4113dSnw141292} {1.1 22}
102*c5c4113dSnw141292
103*c5c4113dSnw141292set long {This is a string that is too big to fit inside a NBFS buffer}
104*c5c4113dSnw141292do_test select1-2.0 {
105*c5c4113dSnw141292  execsql "
106*c5c4113dSnw141292    DROP TABLE test2;
107*c5c4113dSnw141292    DELETE FROM test1;
108*c5c4113dSnw141292    INSERT INTO test1 VALUES(11,22);
109*c5c4113dSnw141292    INSERT INTO test1 VALUES(33,44);
110*c5c4113dSnw141292    CREATE TABLE t3(a,b);
111*c5c4113dSnw141292    INSERT INTO t3 VALUES('abc',NULL);
112*c5c4113dSnw141292    INSERT INTO t3 VALUES(NULL,'xyz');
113*c5c4113dSnw141292    INSERT INTO t3 SELECT * FROM test1;
114*c5c4113dSnw141292    CREATE TABLE t4(a,b);
115*c5c4113dSnw141292    INSERT INTO t4 VALUES(NULL,'$long');
116*c5c4113dSnw141292    SELECT * FROM t3;
117*c5c4113dSnw141292  "
118*c5c4113dSnw141292} {abc {} {} xyz 11 22 33 44}
119*c5c4113dSnw141292
120*c5c4113dSnw141292# Error messges from sqliteExprCheck
121*c5c4113dSnw141292#
122*c5c4113dSnw141292do_test select1-2.1 {
123*c5c4113dSnw141292  set v [catch {execsql {SELECT count(f1,f2) FROM test1}} msg]
124*c5c4113dSnw141292  lappend v $msg
125*c5c4113dSnw141292} {1 {wrong number of arguments to function count()}}
126*c5c4113dSnw141292do_test select1-2.2 {
127*c5c4113dSnw141292  set v [catch {execsql {SELECT count(f1) FROM test1}} msg]
128*c5c4113dSnw141292  lappend v $msg
129*c5c4113dSnw141292} {0 2}
130*c5c4113dSnw141292do_test select1-2.3 {
131*c5c4113dSnw141292  set v [catch {execsql {SELECT Count() FROM test1}} msg]
132*c5c4113dSnw141292  lappend v $msg
133*c5c4113dSnw141292} {0 2}
134*c5c4113dSnw141292do_test select1-2.4 {
135*c5c4113dSnw141292  set v [catch {execsql {SELECT COUNT(*) FROM test1}} msg]
136*c5c4113dSnw141292  lappend v $msg
137*c5c4113dSnw141292} {0 2}
138*c5c4113dSnw141292do_test select1-2.5 {
139*c5c4113dSnw141292  set v [catch {execsql {SELECT COUNT(*)+1 FROM test1}} msg]
140*c5c4113dSnw141292  lappend v $msg
141*c5c4113dSnw141292} {0 3}
142*c5c4113dSnw141292do_test select1-2.5.1 {
143*c5c4113dSnw141292  execsql {SELECT count(*),count(a),count(b) FROM t3}
144*c5c4113dSnw141292} {4 3 3}
145*c5c4113dSnw141292do_test select1-2.5.2 {
146*c5c4113dSnw141292  execsql {SELECT count(*),count(a),count(b) FROM t4}
147*c5c4113dSnw141292} {1 0 1}
148*c5c4113dSnw141292do_test select1-2.5.3 {
149*c5c4113dSnw141292  execsql {SELECT count(*),count(a),count(b) FROM t4 WHERE b=5}
150*c5c4113dSnw141292} {0 0 0}
151*c5c4113dSnw141292do_test select1-2.6 {
152*c5c4113dSnw141292  set v [catch {execsql {SELECT min(*) FROM test1}} msg]
153*c5c4113dSnw141292  lappend v $msg
154*c5c4113dSnw141292} {1 {wrong number of arguments to function min()}}
155*c5c4113dSnw141292do_test select1-2.7 {
156*c5c4113dSnw141292  set v [catch {execsql {SELECT Min(f1) FROM test1}} msg]
157*c5c4113dSnw141292  lappend v $msg
158*c5c4113dSnw141292} {0 11}
159*c5c4113dSnw141292do_test select1-2.8 {
160*c5c4113dSnw141292  set v [catch {execsql {SELECT MIN(f1,f2) FROM test1}} msg]
161*c5c4113dSnw141292  lappend v [lsort $msg]
162*c5c4113dSnw141292} {0 {11 33}}
163*c5c4113dSnw141292do_test select1-2.8.1 {
164*c5c4113dSnw141292  execsql {SELECT coalesce(min(a),'xyzzy') FROM t3}
165*c5c4113dSnw141292} {11}
166*c5c4113dSnw141292do_test select1-2.8.2 {
167*c5c4113dSnw141292  execsql {SELECT min(coalesce(a,'xyzzy')) FROM t3}
168*c5c4113dSnw141292} {11}
169*c5c4113dSnw141292do_test select1-2.8.3 {
170*c5c4113dSnw141292  execsql {SELECT min(b), min(b) FROM t4}
171*c5c4113dSnw141292} [list $long $long]
172*c5c4113dSnw141292do_test select1-2.9 {
173*c5c4113dSnw141292  set v [catch {execsql {SELECT MAX(*) FROM test1}} msg]
174*c5c4113dSnw141292  lappend v $msg
175*c5c4113dSnw141292} {1 {wrong number of arguments to function MAX()}}
176*c5c4113dSnw141292do_test select1-2.10 {
177*c5c4113dSnw141292  set v [catch {execsql {SELECT Max(f1) FROM test1}} msg]
178*c5c4113dSnw141292  lappend v $msg
179*c5c4113dSnw141292} {0 33}
180*c5c4113dSnw141292do_test select1-2.11 {
181*c5c4113dSnw141292  set v [catch {execsql {SELECT max(f1,f2) FROM test1}} msg]
182*c5c4113dSnw141292  lappend v [lsort $msg]
183*c5c4113dSnw141292} {0 {22 44}}
184*c5c4113dSnw141292do_test select1-2.12 {
185*c5c4113dSnw141292  set v [catch {execsql {SELECT MAX(f1,f2)+1 FROM test1}} msg]
186*c5c4113dSnw141292  lappend v [lsort $msg]
187*c5c4113dSnw141292} {0 {23 45}}
188*c5c4113dSnw141292do_test select1-2.13 {
189*c5c4113dSnw141292  set v [catch {execsql {SELECT MAX(f1)+1 FROM test1}} msg]
190*c5c4113dSnw141292  lappend v $msg
191*c5c4113dSnw141292} {0 34}
192*c5c4113dSnw141292do_test select1-2.13.1 {
193*c5c4113dSnw141292  execsql {SELECT coalesce(max(a),'xyzzy') FROM t3}
194*c5c4113dSnw141292} {abc}
195*c5c4113dSnw141292do_test select1-2.13.2 {
196*c5c4113dSnw141292  execsql {SELECT max(coalesce(a,'xyzzy')) FROM t3}
197*c5c4113dSnw141292} {xyzzy}
198*c5c4113dSnw141292do_test select1-2.14 {
199*c5c4113dSnw141292  set v [catch {execsql {SELECT SUM(*) FROM test1}} msg]
200*c5c4113dSnw141292  lappend v $msg
201*c5c4113dSnw141292} {1 {wrong number of arguments to function SUM()}}
202*c5c4113dSnw141292do_test select1-2.15 {
203*c5c4113dSnw141292  set v [catch {execsql {SELECT Sum(f1) FROM test1}} msg]
204*c5c4113dSnw141292  lappend v $msg
205*c5c4113dSnw141292} {0 44}
206*c5c4113dSnw141292do_test select1-2.16 {
207*c5c4113dSnw141292  set v [catch {execsql {SELECT sum(f1,f2) FROM test1}} msg]
208*c5c4113dSnw141292  lappend v $msg
209*c5c4113dSnw141292} {1 {wrong number of arguments to function sum()}}
210*c5c4113dSnw141292do_test select1-2.17 {
211*c5c4113dSnw141292  set v [catch {execsql {SELECT SUM(f1)+1 FROM test1}} msg]
212*c5c4113dSnw141292  lappend v $msg
213*c5c4113dSnw141292} {0 45}
214*c5c4113dSnw141292do_test select1-2.17.1 {
215*c5c4113dSnw141292  execsql {SELECT sum(a) FROM t3}
216*c5c4113dSnw141292} {44}
217*c5c4113dSnw141292do_test select1-2.18 {
218*c5c4113dSnw141292  set v [catch {execsql {SELECT XYZZY(f1) FROM test1}} msg]
219*c5c4113dSnw141292  lappend v $msg
220*c5c4113dSnw141292} {1 {no such function: XYZZY}}
221*c5c4113dSnw141292do_test select1-2.19 {
222*c5c4113dSnw141292  set v [catch {execsql {SELECT SUM(min(f1,f2)) FROM test1}} msg]
223*c5c4113dSnw141292  lappend v $msg
224*c5c4113dSnw141292} {0 44}
225*c5c4113dSnw141292do_test select1-2.20 {
226*c5c4113dSnw141292  set v [catch {execsql {SELECT SUM(min(f1)) FROM test1}} msg]
227*c5c4113dSnw141292  lappend v $msg
228*c5c4113dSnw141292} {1 {misuse of aggregate function min()}}
229*c5c4113dSnw141292
230*c5c4113dSnw141292# WHERE clause expressions
231*c5c4113dSnw141292#
232*c5c4113dSnw141292do_test select1-3.1 {
233*c5c4113dSnw141292  set v [catch {execsql {SELECT f1 FROM test1 WHERE f1<11}} msg]
234*c5c4113dSnw141292  lappend v $msg
235*c5c4113dSnw141292} {0 {}}
236*c5c4113dSnw141292do_test select1-3.2 {
237*c5c4113dSnw141292  set v [catch {execsql {SELECT f1 FROM test1 WHERE f1<=11}} msg]
238*c5c4113dSnw141292  lappend v $msg
239*c5c4113dSnw141292} {0 11}
240*c5c4113dSnw141292do_test select1-3.3 {
241*c5c4113dSnw141292  set v [catch {execsql {SELECT f1 FROM test1 WHERE f1=11}} msg]
242*c5c4113dSnw141292  lappend v $msg
243*c5c4113dSnw141292} {0 11}
244*c5c4113dSnw141292do_test select1-3.4 {
245*c5c4113dSnw141292  set v [catch {execsql {SELECT f1 FROM test1 WHERE f1>=11}} msg]
246*c5c4113dSnw141292  lappend v [lsort $msg]
247*c5c4113dSnw141292} {0 {11 33}}
248*c5c4113dSnw141292do_test select1-3.5 {
249*c5c4113dSnw141292  set v [catch {execsql {SELECT f1 FROM test1 WHERE f1>11}} msg]
250*c5c4113dSnw141292  lappend v [lsort $msg]
251*c5c4113dSnw141292} {0 33}
252*c5c4113dSnw141292do_test select1-3.6 {
253*c5c4113dSnw141292  set v [catch {execsql {SELECT f1 FROM test1 WHERE f1!=11}} msg]
254*c5c4113dSnw141292  lappend v [lsort $msg]
255*c5c4113dSnw141292} {0 33}
256*c5c4113dSnw141292do_test select1-3.7 {
257*c5c4113dSnw141292  set v [catch {execsql {SELECT f1 FROM test1 WHERE min(f1,f2)!=11}} msg]
258*c5c4113dSnw141292  lappend v [lsort $msg]
259*c5c4113dSnw141292} {0 33}
260*c5c4113dSnw141292do_test select1-3.8 {
261*c5c4113dSnw141292  set v [catch {execsql {SELECT f1 FROM test1 WHERE max(f1,f2)!=11}} msg]
262*c5c4113dSnw141292  lappend v [lsort $msg]
263*c5c4113dSnw141292} {0 {11 33}}
264*c5c4113dSnw141292do_test select1-3.9 {
265*c5c4113dSnw141292  set v [catch {execsql {SELECT f1 FROM test1 WHERE count(f1,f2)!=11}} msg]
266*c5c4113dSnw141292  lappend v $msg
267*c5c4113dSnw141292} {1 {wrong number of arguments to function count()}}
268*c5c4113dSnw141292
269*c5c4113dSnw141292# ORDER BY expressions
270*c5c4113dSnw141292#
271*c5c4113dSnw141292do_test select1-4.1 {
272*c5c4113dSnw141292  set v [catch {execsql {SELECT f1 FROM test1 ORDER BY f1}} msg]
273*c5c4113dSnw141292  lappend v $msg
274*c5c4113dSnw141292} {0 {11 33}}
275*c5c4113dSnw141292do_test select1-4.2 {
276*c5c4113dSnw141292  set v [catch {execsql {SELECT f1 FROM test1 ORDER BY -f1}} msg]
277*c5c4113dSnw141292  lappend v $msg
278*c5c4113dSnw141292} {0 {33 11}}
279*c5c4113dSnw141292do_test select1-4.3 {
280*c5c4113dSnw141292  set v [catch {execsql {SELECT f1 FROM test1 ORDER BY min(f1,f2)}} msg]
281*c5c4113dSnw141292  lappend v $msg
282*c5c4113dSnw141292} {0 {11 33}}
283*c5c4113dSnw141292do_test select1-4.4 {
284*c5c4113dSnw141292  set v [catch {execsql {SELECT f1 FROM test1 ORDER BY min(f1)}} msg]
285*c5c4113dSnw141292  lappend v $msg
286*c5c4113dSnw141292} {1 {misuse of aggregate function min()}}
287*c5c4113dSnw141292do_test select1-4.5 {
288*c5c4113dSnw141292  catchsql {
289*c5c4113dSnw141292    SELECT f1 FROM test1 ORDER BY 8.4;
290*c5c4113dSnw141292  }
291*c5c4113dSnw141292} {1 {ORDER BY terms must not be non-integer constants}}
292*c5c4113dSnw141292do_test select1-4.6 {
293*c5c4113dSnw141292  catchsql {
294*c5c4113dSnw141292    SELECT f1 FROM test1 ORDER BY '8.4';
295*c5c4113dSnw141292  }
296*c5c4113dSnw141292} {1 {ORDER BY terms must not be non-integer constants}}
297*c5c4113dSnw141292do_test select1-4.7 {
298*c5c4113dSnw141292  catchsql {
299*c5c4113dSnw141292    SELECT f1 FROM test1 ORDER BY 'xyz';
300*c5c4113dSnw141292  }
301*c5c4113dSnw141292} {1 {ORDER BY terms must not be non-integer constants}}
302*c5c4113dSnw141292do_test select1-4.8 {
303*c5c4113dSnw141292  execsql {
304*c5c4113dSnw141292    CREATE TABLE t5(a,b);
305*c5c4113dSnw141292    INSERT INTO t5 VALUES(1,10);
306*c5c4113dSnw141292    INSERT INTO t5 VALUES(2,9);
307*c5c4113dSnw141292    SELECT * FROM t5 ORDER BY 1;
308*c5c4113dSnw141292  }
309*c5c4113dSnw141292} {1 10 2 9}
310*c5c4113dSnw141292do_test select1-4.9 {
311*c5c4113dSnw141292  execsql {
312*c5c4113dSnw141292    SELECT * FROM t5 ORDER BY 2;
313*c5c4113dSnw141292  }
314*c5c4113dSnw141292} {2 9 1 10}
315*c5c4113dSnw141292do_test select1-4.10 {
316*c5c4113dSnw141292  catchsql {
317*c5c4113dSnw141292    SELECT * FROM t5 ORDER BY 3;
318*c5c4113dSnw141292  }
319*c5c4113dSnw141292} {1 {ORDER BY column number 3 out of range - should be between 1 and 2}}
320*c5c4113dSnw141292do_test select1-4.11 {
321*c5c4113dSnw141292  execsql {
322*c5c4113dSnw141292    INSERT INTO t5 VALUES(3,10);
323*c5c4113dSnw141292    SELECT * FROM t5 ORDER BY 2, 1 DESC;
324*c5c4113dSnw141292  }
325*c5c4113dSnw141292} {2 9 3 10 1 10}
326*c5c4113dSnw141292do_test select1-4.12 {
327*c5c4113dSnw141292  execsql {
328*c5c4113dSnw141292    SELECT * FROM t5 ORDER BY 1 DESC, b;
329*c5c4113dSnw141292  }
330*c5c4113dSnw141292} {3 10 2 9 1 10}
331*c5c4113dSnw141292do_test select1-4.13 {
332*c5c4113dSnw141292  execsql {
333*c5c4113dSnw141292    SELECT * FROM t5 ORDER BY b DESC, 1;
334*c5c4113dSnw141292  }
335*c5c4113dSnw141292} {1 10 3 10 2 9}
336*c5c4113dSnw141292
337*c5c4113dSnw141292
338*c5c4113dSnw141292# ORDER BY ignored on an aggregate query
339*c5c4113dSnw141292#
340*c5c4113dSnw141292do_test select1-5.1 {
341*c5c4113dSnw141292  set v [catch {execsql {SELECT max(f1) FROM test1 ORDER BY f2}} msg]
342*c5c4113dSnw141292  lappend v $msg
343*c5c4113dSnw141292} {0 33}
344*c5c4113dSnw141292
345*c5c4113dSnw141292execsql {CREATE TABLE test2(t1 test, t2 text)}
346*c5c4113dSnw141292execsql {INSERT INTO test2 VALUES('abc','xyz')}
347*c5c4113dSnw141292
348*c5c4113dSnw141292# Check for column naming
349*c5c4113dSnw141292#
350*c5c4113dSnw141292do_test select1-6.1 {
351*c5c4113dSnw141292  set v [catch {execsql2 {SELECT f1 FROM test1 ORDER BY f2}} msg]
352*c5c4113dSnw141292  lappend v $msg
353*c5c4113dSnw141292} {0 {f1 11 f1 33}}
354*c5c4113dSnw141292do_test select1-6.1.1 {
355*c5c4113dSnw141292  execsql {PRAGMA full_column_names=on}
356*c5c4113dSnw141292  set v [catch {execsql2 {SELECT f1 FROM test1 ORDER BY f2}} msg]
357*c5c4113dSnw141292  lappend v $msg
358*c5c4113dSnw141292} {0 {test1.f1 11 test1.f1 33}}
359*c5c4113dSnw141292do_test select1-6.1.2 {
360*c5c4113dSnw141292  set v [catch {execsql2 {SELECT f1 as 'f1' FROM test1 ORDER BY f2}} msg]
361*c5c4113dSnw141292  lappend v $msg
362*c5c4113dSnw141292} {0 {f1 11 f1 33}}
363*c5c4113dSnw141292do_test select1-6.1.3 {
364*c5c4113dSnw141292  set v [catch {execsql2 {SELECT * FROM test1 WHERE f1==11}} msg]
365*c5c4113dSnw141292  lappend v $msg
366*c5c4113dSnw141292} {0 {test1.f1 11 test1.f2 22}}
367*c5c4113dSnw141292do_test select1-6.1.4 {
368*c5c4113dSnw141292  set v [catch {execsql2 {SELECT DISTINCT * FROM test1 WHERE f1==11}} msg]
369*c5c4113dSnw141292  execsql {PRAGMA full_column_names=off}
370*c5c4113dSnw141292  lappend v $msg
371*c5c4113dSnw141292} {0 {test1.f1 11 test1.f2 22}}
372*c5c4113dSnw141292do_test select1-6.1.5 {
373*c5c4113dSnw141292  set v [catch {execsql2 {SELECT * FROM test1 WHERE f1==11}} msg]
374*c5c4113dSnw141292  lappend v $msg
375*c5c4113dSnw141292} {0 {f1 11 f2 22}}
376*c5c4113dSnw141292do_test select1-6.1.6 {
377*c5c4113dSnw141292  set v [catch {execsql2 {SELECT DISTINCT * FROM test1 WHERE f1==11}} msg]
378*c5c4113dSnw141292  lappend v $msg
379*c5c4113dSnw141292} {0 {f1 11 f2 22}}
380*c5c4113dSnw141292do_test select1-6.2 {
381*c5c4113dSnw141292  set v [catch {execsql2 {SELECT f1 as xyzzy FROM test1 ORDER BY f2}} msg]
382*c5c4113dSnw141292  lappend v $msg
383*c5c4113dSnw141292} {0 {xyzzy 11 xyzzy 33}}
384*c5c4113dSnw141292do_test select1-6.3 {
385*c5c4113dSnw141292  set v [catch {execsql2 {SELECT f1 as "xyzzy" FROM test1 ORDER BY f2}} msg]
386*c5c4113dSnw141292  lappend v $msg
387*c5c4113dSnw141292} {0 {xyzzy 11 xyzzy 33}}
388*c5c4113dSnw141292do_test select1-6.3.1 {
389*c5c4113dSnw141292  set v [catch {execsql2 {SELECT f1 as 'xyzzy ' FROM test1 ORDER BY f2}} msg]
390*c5c4113dSnw141292  lappend v $msg
391*c5c4113dSnw141292} {0 {{xyzzy } 11 {xyzzy } 33}}
392*c5c4113dSnw141292do_test select1-6.4 {
393*c5c4113dSnw141292  set v [catch {execsql2 {SELECT f1+F2 as xyzzy FROM test1 ORDER BY f2}} msg]
394*c5c4113dSnw141292  lappend v $msg
395*c5c4113dSnw141292} {0 {xyzzy 33 xyzzy 77}}
396*c5c4113dSnw141292do_test select1-6.4a {
397*c5c4113dSnw141292  set v [catch {execsql2 {SELECT f1+F2 FROM test1 ORDER BY f2}} msg]
398*c5c4113dSnw141292  lappend v $msg
399*c5c4113dSnw141292} {0 {f1+F2 33 f1+F2 77}}
400*c5c4113dSnw141292do_test select1-6.5 {
401*c5c4113dSnw141292  set v [catch {execsql2 {SELECT test1.f1+F2 FROM test1 ORDER BY f2}} msg]
402*c5c4113dSnw141292  lappend v $msg
403*c5c4113dSnw141292} {0 {test1.f1+F2 33 test1.f1+F2 77}}
404*c5c4113dSnw141292do_test select1-6.5.1 {
405*c5c4113dSnw141292  execsql2 {PRAGMA full_column_names=on}
406*c5c4113dSnw141292  set v [catch {execsql2 {SELECT test1.f1+F2 FROM test1 ORDER BY f2}} msg]
407*c5c4113dSnw141292  execsql2 {PRAGMA full_column_names=off}
408*c5c4113dSnw141292  lappend v $msg
409*c5c4113dSnw141292} {0 {test1.f1+F2 33 test1.f1+F2 77}}
410*c5c4113dSnw141292do_test select1-6.6 {
411*c5c4113dSnw141292  set v [catch {execsql2 {SELECT test1.f1+F2, t1 FROM test1, test2
412*c5c4113dSnw141292         ORDER BY f2}} msg]
413*c5c4113dSnw141292  lappend v $msg
414*c5c4113dSnw141292} {0 {test1.f1+F2 33 t1 abc test1.f1+F2 77 t1 abc}}
415*c5c4113dSnw141292do_test select1-6.7 {
416*c5c4113dSnw141292  set v [catch {execsql2 {SELECT A.f1, t1 FROM test1 as A, test2
417*c5c4113dSnw141292         ORDER BY f2}} msg]
418*c5c4113dSnw141292  lappend v $msg
419*c5c4113dSnw141292} {0 {A.f1 11 t1 abc A.f1 33 t1 abc}}
420*c5c4113dSnw141292do_test select1-6.8 {
421*c5c4113dSnw141292  set v [catch {execsql2 {SELECT A.f1, f1 FROM test1 as A, test1 as B
422*c5c4113dSnw141292         ORDER BY f2}} msg]
423*c5c4113dSnw141292  lappend v $msg
424*c5c4113dSnw141292} {1 {ambiguous column name: f1}}
425*c5c4113dSnw141292do_test select1-6.8b {
426*c5c4113dSnw141292  set v [catch {execsql2 {SELECT A.f1, B.f1 FROM test1 as A, test1 as B
427*c5c4113dSnw141292         ORDER BY f2}} msg]
428*c5c4113dSnw141292  lappend v $msg
429*c5c4113dSnw141292} {1 {ambiguous column name: f2}}
430*c5c4113dSnw141292do_test select1-6.8c {
431*c5c4113dSnw141292  set v [catch {execsql2 {SELECT A.f1, f1 FROM test1 as A, test1 as A
432*c5c4113dSnw141292         ORDER BY f2}} msg]
433*c5c4113dSnw141292  lappend v $msg
434*c5c4113dSnw141292} {1 {ambiguous column name: A.f1}}
435*c5c4113dSnw141292do_test select1-6.9 {
436*c5c4113dSnw141292  set v [catch {execsql2 {SELECT A.f1, B.f1 FROM test1 as A, test1 as B
437*c5c4113dSnw141292         ORDER BY A.f1, B.f1}} msg]
438*c5c4113dSnw141292  lappend v $msg
439*c5c4113dSnw141292} {0 {A.f1 11 B.f1 11 A.f1 11 B.f1 33 A.f1 33 B.f1 11 A.f1 33 B.f1 33}}
440*c5c4113dSnw141292do_test select1-6.10 {
441*c5c4113dSnw141292  set v [catch {execsql2 {
442*c5c4113dSnw141292    SELECT f1 FROM test1 UNION SELECT f2 FROM test1
443*c5c4113dSnw141292    ORDER BY f2;
444*c5c4113dSnw141292  }} msg]
445*c5c4113dSnw141292  lappend v $msg
446*c5c4113dSnw141292} {0 {f2 11 f2 22 f2 33 f2 44}}
447*c5c4113dSnw141292do_test select1-6.11 {
448*c5c4113dSnw141292  set v [catch {execsql2 {
449*c5c4113dSnw141292    SELECT f1 FROM test1 UNION SELECT f2+100 FROM test1
450*c5c4113dSnw141292    ORDER BY f2+100;
451*c5c4113dSnw141292  }} msg]
452*c5c4113dSnw141292  lappend v $msg
453*c5c4113dSnw141292} {0 {f2+100 11 f2+100 33 f2+100 122 f2+100 144}}
454*c5c4113dSnw141292
455*c5c4113dSnw141292do_test select1-7.1 {
456*c5c4113dSnw141292  set v [catch {execsql {
457*c5c4113dSnw141292     SELECT f1 FROM test1 WHERE f2=;
458*c5c4113dSnw141292  }} msg]
459*c5c4113dSnw141292  lappend v $msg
460*c5c4113dSnw141292} {1 {near ";": syntax error}}
461*c5c4113dSnw141292do_test select1-7.2 {
462*c5c4113dSnw141292  set v [catch {execsql {
463*c5c4113dSnw141292     SELECT f1 FROM test1 UNION SELECT WHERE;
464*c5c4113dSnw141292  }} msg]
465*c5c4113dSnw141292  lappend v $msg
466*c5c4113dSnw141292} {1 {near "WHERE": syntax error}}
467*c5c4113dSnw141292do_test select1-7.3 {
468*c5c4113dSnw141292  set v [catch {execsql {SELECT f1 FROM test1 as 'hi', test2 as}} msg]
469*c5c4113dSnw141292  lappend v $msg
470*c5c4113dSnw141292} {1 {near "as": syntax error}}
471*c5c4113dSnw141292do_test select1-7.4 {
472*c5c4113dSnw141292  set v [catch {execsql {
473*c5c4113dSnw141292     SELECT f1 FROM test1 ORDER BY;
474*c5c4113dSnw141292  }} msg]
475*c5c4113dSnw141292  lappend v $msg
476*c5c4113dSnw141292} {1 {near ";": syntax error}}
477*c5c4113dSnw141292do_test select1-7.5 {
478*c5c4113dSnw141292  set v [catch {execsql {
479*c5c4113dSnw141292     SELECT f1 FROM test1 ORDER BY f1 desc, f2 where;
480*c5c4113dSnw141292  }} msg]
481*c5c4113dSnw141292  lappend v $msg
482*c5c4113dSnw141292} {1 {near "where": syntax error}}
483*c5c4113dSnw141292do_test select1-7.6 {
484*c5c4113dSnw141292  set v [catch {execsql {
485*c5c4113dSnw141292     SELECT count(f1,f2 FROM test1;
486*c5c4113dSnw141292  }} msg]
487*c5c4113dSnw141292  lappend v $msg
488*c5c4113dSnw141292} {1 {near "FROM": syntax error}}
489*c5c4113dSnw141292do_test select1-7.7 {
490*c5c4113dSnw141292  set v [catch {execsql {
491*c5c4113dSnw141292     SELECT count(f1,f2+) FROM test1;
492*c5c4113dSnw141292  }} msg]
493*c5c4113dSnw141292  lappend v $msg
494*c5c4113dSnw141292} {1 {near ")": syntax error}}
495*c5c4113dSnw141292do_test select1-7.8 {
496*c5c4113dSnw141292  set v [catch {execsql {
497*c5c4113dSnw141292     SELECT f1 FROM test1 ORDER BY f2, f1+;
498*c5c4113dSnw141292  }} msg]
499*c5c4113dSnw141292  lappend v $msg
500*c5c4113dSnw141292} {1 {near ";": syntax error}}
501*c5c4113dSnw141292
502*c5c4113dSnw141292do_test select1-8.1 {
503*c5c4113dSnw141292  execsql {SELECT f1 FROM test1 WHERE 4.3+2.4 OR 1 ORDER BY f1}
504*c5c4113dSnw141292} {11 33}
505*c5c4113dSnw141292do_test select1-8.2 {
506*c5c4113dSnw141292  execsql {
507*c5c4113dSnw141292    SELECT f1 FROM test1 WHERE ('x' || f1) BETWEEN 'x10' AND 'x20'
508*c5c4113dSnw141292    ORDER BY f1
509*c5c4113dSnw141292  }
510*c5c4113dSnw141292} {11}
511*c5c4113dSnw141292do_test select1-8.3 {
512*c5c4113dSnw141292  execsql {
513*c5c4113dSnw141292    SELECT f1 FROM test1 WHERE 5-3==2
514*c5c4113dSnw141292    ORDER BY f1
515*c5c4113dSnw141292  }
516*c5c4113dSnw141292} {11 33}
517*c5c4113dSnw141292do_test select1-8.4 {
518*c5c4113dSnw141292  execsql {
519*c5c4113dSnw141292    SELECT coalesce(f1/(f1-11),'x'),
520*c5c4113dSnw141292           coalesce(min(f1/(f1-11),5),'y'),
521*c5c4113dSnw141292           coalesce(max(f1/(f1-33),6),'z')
522*c5c4113dSnw141292    FROM test1 ORDER BY f1
523*c5c4113dSnw141292  }
524*c5c4113dSnw141292} {x y 6 1.5 1.5 z}
525*c5c4113dSnw141292do_test select1-8.5 {
526*c5c4113dSnw141292  execsql {
527*c5c4113dSnw141292    SELECT min(1,2,3), -max(1,2,3)
528*c5c4113dSnw141292    FROM test1 ORDER BY f1
529*c5c4113dSnw141292  }
530*c5c4113dSnw141292} {1 -3 1 -3}
531*c5c4113dSnw141292
532*c5c4113dSnw141292
533*c5c4113dSnw141292# Check the behavior when the result set is empty
534*c5c4113dSnw141292#
535*c5c4113dSnw141292do_test select1-9.1 {
536*c5c4113dSnw141292  catch {unset r}
537*c5c4113dSnw141292  set r(*) {}
538*c5c4113dSnw141292  db eval {SELECT * FROM test1 WHERE f1<0} r {}
539*c5c4113dSnw141292  set r(*)
540*c5c4113dSnw141292} {}
541*c5c4113dSnw141292do_test select1-9.2 {
542*c5c4113dSnw141292  execsql {PRAGMA empty_result_callbacks=on}
543*c5c4113dSnw141292  set r(*) {}
544*c5c4113dSnw141292  db eval {SELECT * FROM test1 WHERE f1<0} r {}
545*c5c4113dSnw141292  set r(*)
546*c5c4113dSnw141292} {f1 f2}
547*c5c4113dSnw141292do_test select1-9.3 {
548*c5c4113dSnw141292  set r(*) {}
549*c5c4113dSnw141292  db eval {SELECT * FROM test1 WHERE f1<(select count(*) from test2)} r {}
550*c5c4113dSnw141292  set r(*)
551*c5c4113dSnw141292} {f1 f2}
552*c5c4113dSnw141292do_test select1-9.4 {
553*c5c4113dSnw141292  set r(*) {}
554*c5c4113dSnw141292  db eval {SELECT * FROM test1 ORDER BY f1} r {}
555*c5c4113dSnw141292  set r(*)
556*c5c4113dSnw141292} {f1 f2}
557*c5c4113dSnw141292do_test select1-9.5 {
558*c5c4113dSnw141292  set r(*) {}
559*c5c4113dSnw141292  db eval {SELECT * FROM test1 WHERE f1<0 ORDER BY f1} r {}
560*c5c4113dSnw141292  set r(*)
561*c5c4113dSnw141292} {f1 f2}
562*c5c4113dSnw141292unset r
563*c5c4113dSnw141292
564*c5c4113dSnw141292# Check for ORDER BY clauses that refer to an AS name in the column list
565*c5c4113dSnw141292#
566*c5c4113dSnw141292do_test select1-10.1 {
567*c5c4113dSnw141292  execsql {
568*c5c4113dSnw141292    SELECT f1 AS x FROM test1 ORDER BY x
569*c5c4113dSnw141292  }
570*c5c4113dSnw141292} {11 33}
571*c5c4113dSnw141292do_test select1-10.2 {
572*c5c4113dSnw141292  execsql {
573*c5c4113dSnw141292    SELECT f1 AS x FROM test1 ORDER BY -x
574*c5c4113dSnw141292  }
575*c5c4113dSnw141292} {33 11}
576*c5c4113dSnw141292do_test select1-10.3 {
577*c5c4113dSnw141292  execsql {
578*c5c4113dSnw141292    SELECT f1-23 AS x FROM test1 ORDER BY abs(x)
579*c5c4113dSnw141292  }
580*c5c4113dSnw141292} {10 -12}
581*c5c4113dSnw141292do_test select1-10.4 {
582*c5c4113dSnw141292  execsql {
583*c5c4113dSnw141292    SELECT f1-23 AS x FROM test1 ORDER BY -abs(x)
584*c5c4113dSnw141292  }
585*c5c4113dSnw141292} {-12 10}
586*c5c4113dSnw141292do_test select1-10.5 {
587*c5c4113dSnw141292  execsql {
588*c5c4113dSnw141292    SELECT f1-22 AS x, f2-22 as y FROM test1
589*c5c4113dSnw141292  }
590*c5c4113dSnw141292} {-11 0 11 22}
591*c5c4113dSnw141292do_test select1-10.6 {
592*c5c4113dSnw141292  execsql {
593*c5c4113dSnw141292    SELECT f1-22 AS x, f2-22 as y FROM test1 WHERE x>0 AND y<50
594*c5c4113dSnw141292  }
595*c5c4113dSnw141292} {11 22}
596*c5c4113dSnw141292
597*c5c4113dSnw141292# Check the ability to specify "TABLE.*" in the result set of a SELECT
598*c5c4113dSnw141292#
599*c5c4113dSnw141292do_test select1-11.1 {
600*c5c4113dSnw141292  execsql {
601*c5c4113dSnw141292    DELETE FROM t3;
602*c5c4113dSnw141292    DELETE FROM t4;
603*c5c4113dSnw141292    INSERT INTO t3 VALUES(1,2);
604*c5c4113dSnw141292    INSERT INTO t4 VALUES(3,4);
605*c5c4113dSnw141292    SELECT * FROM t3, t4;
606*c5c4113dSnw141292  }
607*c5c4113dSnw141292} {1 2 3 4}
608*c5c4113dSnw141292do_test select1-11.2 {
609*c5c4113dSnw141292  execsql2 {
610*c5c4113dSnw141292    SELECT * FROM t3, t4;
611*c5c4113dSnw141292  }
612*c5c4113dSnw141292} {t3.a 1 t3.b 2 t4.a 3 t4.b 4}
613*c5c4113dSnw141292do_test select1-11.3 {
614*c5c4113dSnw141292  execsql2 {
615*c5c4113dSnw141292    SELECT * FROM t3 AS x, t4 AS y;
616*c5c4113dSnw141292  }
617*c5c4113dSnw141292} {x.a 1 x.b 2 y.a 3 y.b 4}
618*c5c4113dSnw141292do_test select1-11.4.1 {
619*c5c4113dSnw141292  execsql {
620*c5c4113dSnw141292    SELECT t3.*, t4.b FROM t3, t4;
621*c5c4113dSnw141292  }
622*c5c4113dSnw141292} {1 2 4}
623*c5c4113dSnw141292do_test select1-11.4.2 {
624*c5c4113dSnw141292  execsql {
625*c5c4113dSnw141292    SELECT "t3".*, t4.b FROM t3, t4;
626*c5c4113dSnw141292  }
627*c5c4113dSnw141292} {1 2 4}
628*c5c4113dSnw141292do_test select1-11.5 {
629*c5c4113dSnw141292  execsql2 {
630*c5c4113dSnw141292    SELECT t3.*, t4.b FROM t3, t4;
631*c5c4113dSnw141292  }
632*c5c4113dSnw141292} {t3.a 1 t3.b 2 t4.b 4}
633*c5c4113dSnw141292do_test select1-11.6 {
634*c5c4113dSnw141292  execsql2 {
635*c5c4113dSnw141292    SELECT x.*, y.b FROM t3 AS x, t4 AS y;
636*c5c4113dSnw141292  }
637*c5c4113dSnw141292} {x.a 1 x.b 2 y.b 4}
638*c5c4113dSnw141292do_test select1-11.7 {
639*c5c4113dSnw141292  execsql {
640*c5c4113dSnw141292    SELECT t3.b, t4.* FROM t3, t4;
641*c5c4113dSnw141292  }
642*c5c4113dSnw141292} {2 3 4}
643*c5c4113dSnw141292do_test select1-11.8 {
644*c5c4113dSnw141292  execsql2 {
645*c5c4113dSnw141292    SELECT t3.b, t4.* FROM t3, t4;
646*c5c4113dSnw141292  }
647*c5c4113dSnw141292} {t3.b 2 t4.a 3 t4.b 4}
648*c5c4113dSnw141292do_test select1-11.9 {
649*c5c4113dSnw141292  execsql2 {
650*c5c4113dSnw141292    SELECT x.b, y.* FROM t3 AS x, t4 AS y;
651*c5c4113dSnw141292  }
652*c5c4113dSnw141292} {x.b 2 y.a 3 y.b 4}
653*c5c4113dSnw141292do_test select1-11.10 {
654*c5c4113dSnw141292  catchsql {
655*c5c4113dSnw141292    SELECT t5.* FROM t3, t4;
656*c5c4113dSnw141292  }
657*c5c4113dSnw141292} {1 {no such table: t5}}
658*c5c4113dSnw141292do_test select1-11.11 {
659*c5c4113dSnw141292  catchsql {
660*c5c4113dSnw141292    SELECT t3.* FROM t3 AS x, t4;
661*c5c4113dSnw141292  }
662*c5c4113dSnw141292} {1 {no such table: t3}}
663*c5c4113dSnw141292do_test select1-11.12 {
664*c5c4113dSnw141292  execsql2 {
665*c5c4113dSnw141292    SELECT t3.* FROM t3, (SELECT max(a), max(b) FROM t4)
666*c5c4113dSnw141292  }
667*c5c4113dSnw141292} {t3.a 1 t3.b 2}
668*c5c4113dSnw141292do_test select1-11.13 {
669*c5c4113dSnw141292  execsql2 {
670*c5c4113dSnw141292    SELECT t3.* FROM (SELECT max(a), max(b) FROM t4), t3
671*c5c4113dSnw141292  }
672*c5c4113dSnw141292} {t3.a 1 t3.b 2}
673*c5c4113dSnw141292do_test select1-11.14 {
674*c5c4113dSnw141292  execsql2 {
675*c5c4113dSnw141292    SELECT * FROM t3, (SELECT max(a), max(b) FROM t4) AS 'tx'
676*c5c4113dSnw141292  }
677*c5c4113dSnw141292} {t3.a 1 t3.b 2 tx.max(a) 3 tx.max(b) 4}
678*c5c4113dSnw141292do_test select1-11.15 {
679*c5c4113dSnw141292  execsql2 {
680*c5c4113dSnw141292    SELECT y.*, t3.* FROM t3, (SELECT max(a), max(b) FROM t4) AS y
681*c5c4113dSnw141292  }
682*c5c4113dSnw141292} {y.max(a) 3 y.max(b) 4 t3.a 1 t3.b 2}
683*c5c4113dSnw141292do_test select1-11.16 {
684*c5c4113dSnw141292  execsql2 {
685*c5c4113dSnw141292    SELECT y.* FROM t3 as y, t4 as z
686*c5c4113dSnw141292  }
687*c5c4113dSnw141292} {y.a 1 y.b 2}
688*c5c4113dSnw141292
689*c5c4113dSnw141292# Tests of SELECT statements without a FROM clause.
690*c5c4113dSnw141292#
691*c5c4113dSnw141292do_test select1-12.1 {
692*c5c4113dSnw141292  execsql2 {
693*c5c4113dSnw141292    SELECT 1+2+3
694*c5c4113dSnw141292  }
695*c5c4113dSnw141292} {1+2+3 6}
696*c5c4113dSnw141292do_test select1-12.2 {
697*c5c4113dSnw141292  execsql2 {
698*c5c4113dSnw141292    SELECT 1,'hello',2
699*c5c4113dSnw141292  }
700*c5c4113dSnw141292} {1 1 'hello' hello 2 2}
701*c5c4113dSnw141292do_test select1-12.3 {
702*c5c4113dSnw141292  execsql2 {
703*c5c4113dSnw141292    SELECT 1 AS 'a','hello' AS 'b',2 AS 'c'
704*c5c4113dSnw141292  }
705*c5c4113dSnw141292} {a 1 b hello c 2}
706*c5c4113dSnw141292do_test select1-12.4 {
707*c5c4113dSnw141292  execsql {
708*c5c4113dSnw141292    DELETE FROM t3;
709*c5c4113dSnw141292    INSERT INTO t3 VALUES(1,2);
710*c5c4113dSnw141292    SELECT * FROM t3 UNION SELECT 3 AS 'a', 4 ORDER BY a;
711*c5c4113dSnw141292  }
712*c5c4113dSnw141292} {1 2 3 4}
713*c5c4113dSnw141292do_test select1-12.5 {
714*c5c4113dSnw141292  execsql {
715*c5c4113dSnw141292    SELECT 3, 4 UNION SELECT * FROM t3;
716*c5c4113dSnw141292  }
717*c5c4113dSnw141292} {1 2 3 4}
718*c5c4113dSnw141292do_test select1-12.6 {
719*c5c4113dSnw141292  execsql {
720*c5c4113dSnw141292    SELECT * FROM t3 WHERE a=(SELECT 1);
721*c5c4113dSnw141292  }
722*c5c4113dSnw141292} {1 2}
723*c5c4113dSnw141292do_test select1-12.7 {
724*c5c4113dSnw141292  execsql {
725*c5c4113dSnw141292    SELECT * FROM t3 WHERE a=(SELECT 2);
726*c5c4113dSnw141292  }
727*c5c4113dSnw141292} {}
728*c5c4113dSnw141292do_test select1-12.8 {
729*c5c4113dSnw141292  execsql2 {
730*c5c4113dSnw141292    SELECT x FROM (
731*c5c4113dSnw141292      SELECT a,b FROM t3 UNION SELECT a AS 'x', b AS 'y' FROM t4 ORDER BY a,b
732*c5c4113dSnw141292    ) ORDER BY x;
733*c5c4113dSnw141292  }
734*c5c4113dSnw141292} {x 1 x 3}
735*c5c4113dSnw141292do_test select1-12.9 {
736*c5c4113dSnw141292  execsql2 {
737*c5c4113dSnw141292    SELECT z.x FROM (
738*c5c4113dSnw141292      SELECT a,b FROM t3 UNION SELECT a AS 'x', b AS 'y' FROM t4 ORDER BY a,b
739*c5c4113dSnw141292    ) AS 'z' ORDER BY x;
740*c5c4113dSnw141292  }
741*c5c4113dSnw141292} {z.x 1 z.x 3}
742*c5c4113dSnw141292
743*c5c4113dSnw141292
744*c5c4113dSnw141292finish_test
745