xref: /titanic_52/usr/src/lib/libsqlite/test/view.test (revision c5c4113dfcabb1eed3d4bdf7609de5170027a794)
1*c5c4113dSnw141292
2*c5c4113dSnw141292#pragma ident	"%Z%%M%	%I%	%E% SMI"
3*c5c4113dSnw141292
4*c5c4113dSnw141292# 2002 February 26
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 VIEW statements.
16*c5c4113dSnw141292#
17*c5c4113dSnw141292# $Id: view.test,v 1.16.2.1 2004/07/20 00:20:47 drh Exp $
18*c5c4113dSnw141292set testdir [file dirname $argv0]
19*c5c4113dSnw141292source $testdir/tester.tcl
20*c5c4113dSnw141292
21*c5c4113dSnw141292do_test view-1.0 {
22*c5c4113dSnw141292  execsql {
23*c5c4113dSnw141292    CREATE TABLE t1(a,b,c);
24*c5c4113dSnw141292    INSERT INTO t1 VALUES(1,2,3);
25*c5c4113dSnw141292    INSERT INTO t1 VALUES(4,5,6);
26*c5c4113dSnw141292    INSERT INTO t1 VALUES(7,8,9);
27*c5c4113dSnw141292    SELECT * FROM t1;
28*c5c4113dSnw141292  }
29*c5c4113dSnw141292} {1 2 3 4 5 6 7 8 9}
30*c5c4113dSnw141292
31*c5c4113dSnw141292do_test view-1.1 {
32*c5c4113dSnw141292  execsql {
33*c5c4113dSnw141292    BEGIN;
34*c5c4113dSnw141292    CREATE VIEW v1 AS SELECT a,b FROM t1;
35*c5c4113dSnw141292    SELECT * FROM v1 ORDER BY a;
36*c5c4113dSnw141292  }
37*c5c4113dSnw141292} {1 2 4 5 7 8}
38*c5c4113dSnw141292do_test view-1.2 {
39*c5c4113dSnw141292  catchsql {
40*c5c4113dSnw141292    ROLLBACK;
41*c5c4113dSnw141292    SELECT * FROM v1 ORDER BY a;
42*c5c4113dSnw141292  }
43*c5c4113dSnw141292} {1 {no such table: v1}}
44*c5c4113dSnw141292do_test view-1.3 {
45*c5c4113dSnw141292  execsql {
46*c5c4113dSnw141292    CREATE VIEW v1 AS SELECT a,b FROM t1;
47*c5c4113dSnw141292    SELECT * FROM v1 ORDER BY a;
48*c5c4113dSnw141292  }
49*c5c4113dSnw141292} {1 2 4 5 7 8}
50*c5c4113dSnw141292do_test view-1.3.1 {
51*c5c4113dSnw141292  db close
52*c5c4113dSnw141292  sqlite db test.db
53*c5c4113dSnw141292  execsql {
54*c5c4113dSnw141292    SELECT * FROM v1 ORDER BY a;
55*c5c4113dSnw141292  }
56*c5c4113dSnw141292} {1 2 4 5 7 8}
57*c5c4113dSnw141292do_test view-1.4 {
58*c5c4113dSnw141292  catchsql {
59*c5c4113dSnw141292    DROP VIEW v1;
60*c5c4113dSnw141292    SELECT * FROM v1 ORDER BY a;
61*c5c4113dSnw141292  }
62*c5c4113dSnw141292} {1 {no such table: v1}}
63*c5c4113dSnw141292do_test view-1.5 {
64*c5c4113dSnw141292  execsql {
65*c5c4113dSnw141292    CREATE VIEW v1 AS SELECT a,b FROM t1;
66*c5c4113dSnw141292    SELECT * FROM v1 ORDER BY a;
67*c5c4113dSnw141292  }
68*c5c4113dSnw141292} {1 2 4 5 7 8}
69*c5c4113dSnw141292do_test view-1.6 {
70*c5c4113dSnw141292  catchsql {
71*c5c4113dSnw141292    DROP TABLE t1;
72*c5c4113dSnw141292    SELECT * FROM v1 ORDER BY a;
73*c5c4113dSnw141292  }
74*c5c4113dSnw141292} {1 {no such table: main.t1}}
75*c5c4113dSnw141292do_test view-1.7 {
76*c5c4113dSnw141292  execsql {
77*c5c4113dSnw141292    CREATE TABLE t1(x,a,b,c);
78*c5c4113dSnw141292    INSERT INTO t1 VALUES(1,2,3,4);
79*c5c4113dSnw141292    INSERT INTO t1 VALUES(4,5,6,7);
80*c5c4113dSnw141292    INSERT INTO t1 VALUES(7,8,9,10);
81*c5c4113dSnw141292    SELECT * FROM v1 ORDER BY a;
82*c5c4113dSnw141292  }
83*c5c4113dSnw141292} {2 3 5 6 8 9}
84*c5c4113dSnw141292do_test view-1.8 {
85*c5c4113dSnw141292  db close
86*c5c4113dSnw141292  sqlite db test.db
87*c5c4113dSnw141292  execsql {
88*c5c4113dSnw141292    SELECT * FROM v1 ORDER BY a;
89*c5c4113dSnw141292  }
90*c5c4113dSnw141292} {2 3 5 6 8 9}
91*c5c4113dSnw141292
92*c5c4113dSnw141292do_test view-2.1 {
93*c5c4113dSnw141292  execsql {
94*c5c4113dSnw141292    CREATE VIEW v2 AS SELECT * FROM t1 WHERE a>5
95*c5c4113dSnw141292  };  # No semicolon
96*c5c4113dSnw141292  execsql2 {
97*c5c4113dSnw141292    SELECT * FROM v2;
98*c5c4113dSnw141292  }
99*c5c4113dSnw141292} {x 7 a 8 b 9 c 10}
100*c5c4113dSnw141292do_test view-2.2 {
101*c5c4113dSnw141292  catchsql {
102*c5c4113dSnw141292    INSERT INTO v2 VALUES(1,2,3,4);
103*c5c4113dSnw141292  }
104*c5c4113dSnw141292} {1 {cannot modify v2 because it is a view}}
105*c5c4113dSnw141292do_test view-2.3 {
106*c5c4113dSnw141292  catchsql {
107*c5c4113dSnw141292    UPDATE v2 SET a=10 WHERE a=5;
108*c5c4113dSnw141292  }
109*c5c4113dSnw141292} {1 {cannot modify v2 because it is a view}}
110*c5c4113dSnw141292do_test view-2.4 {
111*c5c4113dSnw141292  catchsql {
112*c5c4113dSnw141292    DELETE FROM v2;
113*c5c4113dSnw141292  }
114*c5c4113dSnw141292} {1 {cannot modify v2 because it is a view}}
115*c5c4113dSnw141292do_test view-2.5 {
116*c5c4113dSnw141292  execsql {
117*c5c4113dSnw141292    INSERT INTO t1 VALUES(11,12,13,14);
118*c5c4113dSnw141292    SELECT * FROM v2 ORDER BY x;
119*c5c4113dSnw141292  }
120*c5c4113dSnw141292} {7 8 9 10 11 12 13 14}
121*c5c4113dSnw141292do_test view-2.6 {
122*c5c4113dSnw141292  execsql {
123*c5c4113dSnw141292    SELECT x FROM v2 WHERE a>10
124*c5c4113dSnw141292  }
125*c5c4113dSnw141292} {11}
126*c5c4113dSnw141292
127*c5c4113dSnw141292# Test that column name of views are generated correctly.
128*c5c4113dSnw141292#
129*c5c4113dSnw141292do_test view-3.1 {
130*c5c4113dSnw141292  execsql2 {
131*c5c4113dSnw141292    SELECT * FROM v1 LIMIT 1
132*c5c4113dSnw141292  }
133*c5c4113dSnw141292} {a 2 b 3}
134*c5c4113dSnw141292do_test view-3.2 {
135*c5c4113dSnw141292  execsql2 {
136*c5c4113dSnw141292    SELECT * FROM v2 LIMIT 1
137*c5c4113dSnw141292  }
138*c5c4113dSnw141292} {x 7 a 8 b 9 c 10}
139*c5c4113dSnw141292do_test view-3.3 {
140*c5c4113dSnw141292  execsql2 {
141*c5c4113dSnw141292    DROP VIEW v1;
142*c5c4113dSnw141292    CREATE VIEW v1 AS SELECT a AS 'xyz', b+c AS 'pqr', c-b FROM t1;
143*c5c4113dSnw141292    SELECT * FROM v1 LIMIT 1
144*c5c4113dSnw141292  }
145*c5c4113dSnw141292} {xyz 2 pqr 7 c-b 1}
146*c5c4113dSnw141292do_test  view-3.4 {
147*c5c4113dSnw141292  execsql2 {
148*c5c4113dSnw141292    CREATE VIEW v3 AS SELECT a FROM t1 UNION SELECT b FROM t1 ORDER BY b;
149*c5c4113dSnw141292    SELECT * FROM v3 LIMIT 4;
150*c5c4113dSnw141292  }
151*c5c4113dSnw141292} {b 2 b 3 b 5 b 6}
152*c5c4113dSnw141292do_test  view-3.5 {
153*c5c4113dSnw141292  execsql2 {
154*c5c4113dSnw141292    CREATE VIEW v4 AS
155*c5c4113dSnw141292      SELECT a, b FROM t1
156*c5c4113dSnw141292      UNION
157*c5c4113dSnw141292      SELECT b AS 'x', a AS 'y' FROM t1
158*c5c4113dSnw141292      ORDER BY x, y;
159*c5c4113dSnw141292    SELECT y FROM v4 ORDER BY y LIMIT 4;
160*c5c4113dSnw141292  }
161*c5c4113dSnw141292} {y 2 y 3 y 5 y 6}
162*c5c4113dSnw141292
163*c5c4113dSnw141292
164*c5c4113dSnw141292do_test view-4.1 {
165*c5c4113dSnw141292  catchsql {
166*c5c4113dSnw141292    DROP VIEW t1;
167*c5c4113dSnw141292  }
168*c5c4113dSnw141292} {1 {use DROP TABLE to delete table t1}}
169*c5c4113dSnw141292do_test view-4.2 {
170*c5c4113dSnw141292  execsql {
171*c5c4113dSnw141292    SELECT 1 FROM t1 LIMIT 1;
172*c5c4113dSnw141292  }
173*c5c4113dSnw141292} 1
174*c5c4113dSnw141292do_test view-4.3 {
175*c5c4113dSnw141292  catchsql {
176*c5c4113dSnw141292    DROP TABLE v1;
177*c5c4113dSnw141292  }
178*c5c4113dSnw141292} {1 {use DROP VIEW to delete view v1}}
179*c5c4113dSnw141292do_test view-4.4 {
180*c5c4113dSnw141292  execsql {
181*c5c4113dSnw141292     SELECT 1 FROM v1 LIMIT 1;
182*c5c4113dSnw141292  }
183*c5c4113dSnw141292} {1}
184*c5c4113dSnw141292do_test view-4.5 {
185*c5c4113dSnw141292  catchsql {
186*c5c4113dSnw141292    CREATE INDEX i1v1 ON v1(xyz);
187*c5c4113dSnw141292  }
188*c5c4113dSnw141292} {1 {views may not be indexed}}
189*c5c4113dSnw141292
190*c5c4113dSnw141292do_test view-5.1 {
191*c5c4113dSnw141292  execsql {
192*c5c4113dSnw141292    CREATE TABLE t2(y,a);
193*c5c4113dSnw141292    INSERT INTO t2 VALUES(22,2);
194*c5c4113dSnw141292    INSERT INTO t2 VALUES(33,3);
195*c5c4113dSnw141292    INSERT INTO t2 VALUES(44,4);
196*c5c4113dSnw141292    INSERT INTO t2 VALUES(55,5);
197*c5c4113dSnw141292    SELECT * FROM t2;
198*c5c4113dSnw141292  }
199*c5c4113dSnw141292} {22 2 33 3 44 4 55 5}
200*c5c4113dSnw141292do_test view-5.2 {
201*c5c4113dSnw141292  execsql {
202*c5c4113dSnw141292    CREATE VIEW v5 AS
203*c5c4113dSnw141292      SELECT t1.x AS v, t2.y AS w FROM t1 JOIN t2 USING(a);
204*c5c4113dSnw141292    SELECT * FROM v5;
205*c5c4113dSnw141292  }
206*c5c4113dSnw141292} {1 22 4 55}
207*c5c4113dSnw141292
208*c5c4113dSnw141292# Verify that the view v5 gets flattened.  see sqliteFlattenSubquery().
209*c5c4113dSnw141292# Ticket #272
210*c5c4113dSnw141292do_test view-5.3 {
211*c5c4113dSnw141292  lsearch [execsql {
212*c5c4113dSnw141292    EXPLAIN SELECT * FROM v5;
213*c5c4113dSnw141292  }] OpenTemp
214*c5c4113dSnw141292} {-1}
215*c5c4113dSnw141292do_test view-5.4 {
216*c5c4113dSnw141292  execsql {
217*c5c4113dSnw141292    SELECT * FROM v5 AS a, t2 AS b WHERE a.w=b.y;
218*c5c4113dSnw141292  }
219*c5c4113dSnw141292} {1 22 22 2 4 55 55 5}
220*c5c4113dSnw141292do_test view-5.5 {
221*c5c4113dSnw141292  lsearch [execsql {
222*c5c4113dSnw141292    EXPLAIN SELECT * FROM v5 AS a, t2 AS b WHERE a.w=b.y;
223*c5c4113dSnw141292  }] OpenTemp
224*c5c4113dSnw141292} {-1}
225*c5c4113dSnw141292do_test view-5.6 {
226*c5c4113dSnw141292  execsql {
227*c5c4113dSnw141292    SELECT * FROM t2 AS b, v5 AS a WHERE a.w=b.y;
228*c5c4113dSnw141292  }
229*c5c4113dSnw141292} {22 2 1 22 55 5 4 55}
230*c5c4113dSnw141292do_test view-5.7 {
231*c5c4113dSnw141292  lsearch [execsql {
232*c5c4113dSnw141292    EXPLAIN SELECT * FROM t2 AS b, v5 AS a WHERE a.w=b.y;
233*c5c4113dSnw141292  }] OpenTemp
234*c5c4113dSnw141292} {-1}
235*c5c4113dSnw141292do_test view-5.8 {
236*c5c4113dSnw141292  execsql {
237*c5c4113dSnw141292    SELECT * FROM t1 AS a, v5 AS b, t2 AS c WHERE a.x=b.v AND b.w=c.y;
238*c5c4113dSnw141292  }
239*c5c4113dSnw141292} {1 2 3 4 1 22 22 2 4 5 6 7 4 55 55 5}
240*c5c4113dSnw141292do_test view-5.9 {
241*c5c4113dSnw141292  lsearch [execsql {
242*c5c4113dSnw141292    EXPLAIN SELECT * FROM t1 AS a, v5 AS b, t2 AS c WHERE a.x=b.v AND b.w=c.y;
243*c5c4113dSnw141292  }] OpenTemp
244*c5c4113dSnw141292} {-1}
245*c5c4113dSnw141292
246*c5c4113dSnw141292do_test view-6.1 {
247*c5c4113dSnw141292  execsql {
248*c5c4113dSnw141292    SELECT min(x), min(a), min(b), min(c), min(a+b+c) FROM v2;
249*c5c4113dSnw141292  }
250*c5c4113dSnw141292} {7 8 9 10 27}
251*c5c4113dSnw141292do_test view-6.2 {
252*c5c4113dSnw141292  execsql {
253*c5c4113dSnw141292    SELECT max(x), max(a), max(b), max(c), max(a+b+c) FROM v2;
254*c5c4113dSnw141292  }
255*c5c4113dSnw141292} {11 12 13 14 39}
256*c5c4113dSnw141292
257*c5c4113dSnw141292do_test view-7.1 {
258*c5c4113dSnw141292  execsql {
259*c5c4113dSnw141292    CREATE TABLE test1(id integer primary key, a);
260*c5c4113dSnw141292    CREATE TABLE test2(id integer, b);
261*c5c4113dSnw141292    INSERT INTO test1 VALUES(1,2);
262*c5c4113dSnw141292    INSERT INTO test2 VALUES(1,3);
263*c5c4113dSnw141292    CREATE VIEW test AS
264*c5c4113dSnw141292      SELECT test1.id, a, b
265*c5c4113dSnw141292      FROM test1 JOIN test2 ON test2.id=test1.id;
266*c5c4113dSnw141292    SELECT * FROM test;
267*c5c4113dSnw141292  }
268*c5c4113dSnw141292} {1 2 3}
269*c5c4113dSnw141292do_test view-7.2 {
270*c5c4113dSnw141292  db close
271*c5c4113dSnw141292  sqlite db test.db
272*c5c4113dSnw141292  execsql {
273*c5c4113dSnw141292    SELECT * FROM test;
274*c5c4113dSnw141292  }
275*c5c4113dSnw141292} {1 2 3}
276*c5c4113dSnw141292do_test view-7.3 {
277*c5c4113dSnw141292  execsql {
278*c5c4113dSnw141292    DROP VIEW test;
279*c5c4113dSnw141292    CREATE VIEW test AS
280*c5c4113dSnw141292      SELECT test1.id, a, b
281*c5c4113dSnw141292      FROM test1 JOIN test2 USING(id);
282*c5c4113dSnw141292    SELECT * FROM test;
283*c5c4113dSnw141292  }
284*c5c4113dSnw141292} {1 2 3}
285*c5c4113dSnw141292do_test view-7.4 {
286*c5c4113dSnw141292  db close
287*c5c4113dSnw141292  sqlite db test.db
288*c5c4113dSnw141292  execsql {
289*c5c4113dSnw141292    SELECT * FROM test;
290*c5c4113dSnw141292  }
291*c5c4113dSnw141292} {1 2 3}
292*c5c4113dSnw141292do_test view-7.5 {
293*c5c4113dSnw141292  execsql {
294*c5c4113dSnw141292    DROP VIEW test;
295*c5c4113dSnw141292    CREATE VIEW test AS
296*c5c4113dSnw141292      SELECT test1.id, a, b
297*c5c4113dSnw141292      FROM test1 NATURAL JOIN test2;
298*c5c4113dSnw141292    SELECT * FROM test;
299*c5c4113dSnw141292  }
300*c5c4113dSnw141292} {1 2 3}
301*c5c4113dSnw141292do_test view-7.6 {
302*c5c4113dSnw141292  db close
303*c5c4113dSnw141292  sqlite db test.db
304*c5c4113dSnw141292  execsql {
305*c5c4113dSnw141292    SELECT * FROM test;
306*c5c4113dSnw141292  }
307*c5c4113dSnw141292} {1 2 3}
308*c5c4113dSnw141292
309*c5c4113dSnw141292do_test view-8.1 {
310*c5c4113dSnw141292  execsql {
311*c5c4113dSnw141292    CREATE VIEW v6 AS SELECT pqr, xyz FROM v1;
312*c5c4113dSnw141292    SELECT * FROM v6 ORDER BY xyz;
313*c5c4113dSnw141292  }
314*c5c4113dSnw141292} {7 2 13 5 19 8 27 12}
315*c5c4113dSnw141292do_test view-8.2 {
316*c5c4113dSnw141292  db close
317*c5c4113dSnw141292  sqlite db test.db
318*c5c4113dSnw141292  execsql {
319*c5c4113dSnw141292    SELECT * FROM v6 ORDER BY xyz;
320*c5c4113dSnw141292  }
321*c5c4113dSnw141292} {7 2 13 5 19 8 27 12}
322*c5c4113dSnw141292do_test view-8.3 {
323*c5c4113dSnw141292  execsql {
324*c5c4113dSnw141292    CREATE VIEW v7 AS SELECT pqr+xyz AS a FROM v6;
325*c5c4113dSnw141292    SELECT * FROM v7 ORDER BY a;
326*c5c4113dSnw141292  }
327*c5c4113dSnw141292} {9 18 27 39}
328*c5c4113dSnw141292do_test view-8.4 {
329*c5c4113dSnw141292  execsql {
330*c5c4113dSnw141292    CREATE VIEW v8 AS SELECT max(cnt) AS mx FROM
331*c5c4113dSnw141292      (SELECT a%2 AS eo, count(*) AS cnt FROM t1 GROUP BY eo);
332*c5c4113dSnw141292    SELECT * FROM v8;
333*c5c4113dSnw141292  }
334*c5c4113dSnw141292} 3
335*c5c4113dSnw141292do_test view-8.5 {
336*c5c4113dSnw141292  execsql {
337*c5c4113dSnw141292    SELECT mx+10, mx*2 FROM v8;
338*c5c4113dSnw141292  }
339*c5c4113dSnw141292} {13 6}
340*c5c4113dSnw141292do_test view-8.6 {
341*c5c4113dSnw141292  execsql {
342*c5c4113dSnw141292    SELECT mx+10, pqr FROM v6, v8 WHERE xyz=2;
343*c5c4113dSnw141292  }
344*c5c4113dSnw141292} {13 7}
345*c5c4113dSnw141292do_test view-8.7 {
346*c5c4113dSnw141292  execsql {
347*c5c4113dSnw141292    SELECT mx+10, pqr FROM v6, v8 WHERE xyz>2;
348*c5c4113dSnw141292  }
349*c5c4113dSnw141292} {13 13 13 19 13 27}
350*c5c4113dSnw141292
351*c5c4113dSnw141292# Tests for a bug found by Michiel de Wit involving ORDER BY in a VIEW.
352*c5c4113dSnw141292#
353*c5c4113dSnw141292do_test view-9.1 {
354*c5c4113dSnw141292  execsql {
355*c5c4113dSnw141292    INSERT INTO t2 SELECT * FROM t2 WHERE a<5;
356*c5c4113dSnw141292    INSERT INTO t2 SELECT * FROM t2 WHERE a<4;
357*c5c4113dSnw141292    INSERT INTO t2 SELECT * FROM t2 WHERE a<3;
358*c5c4113dSnw141292    SELECT DISTINCT count(*) FROM t2 GROUP BY a ORDER BY 1;
359*c5c4113dSnw141292  }
360*c5c4113dSnw141292} {1 2 4 8}
361*c5c4113dSnw141292do_test view-9.2 {
362*c5c4113dSnw141292  execsql {
363*c5c4113dSnw141292    SELECT DISTINCT count(*) FROM t2 GROUP BY a ORDER BY 1 LIMIT 3;
364*c5c4113dSnw141292  }
365*c5c4113dSnw141292} {1 2 4}
366*c5c4113dSnw141292do_test view-9.3 {
367*c5c4113dSnw141292  execsql {
368*c5c4113dSnw141292    CREATE VIEW v9 AS
369*c5c4113dSnw141292       SELECT DISTINCT count(*) FROM t2 GROUP BY a ORDER BY 1 LIMIT 3;
370*c5c4113dSnw141292    SELECT * FROM v9;
371*c5c4113dSnw141292  }
372*c5c4113dSnw141292} {1 2 4}
373*c5c4113dSnw141292do_test view-9.4 {
374*c5c4113dSnw141292  execsql {
375*c5c4113dSnw141292    SELECT * FROM v9 ORDER BY 1 DESC;
376*c5c4113dSnw141292  }
377*c5c4113dSnw141292} {4 2 1}
378*c5c4113dSnw141292do_test view-9.5 {
379*c5c4113dSnw141292  execsql {
380*c5c4113dSnw141292    CREATE VIEW v10 AS
381*c5c4113dSnw141292       SELECT DISTINCT a, count(*) FROM t2 GROUP BY a ORDER BY 2 LIMIT 3;
382*c5c4113dSnw141292    SELECT * FROM v10;
383*c5c4113dSnw141292  }
384*c5c4113dSnw141292} {5 1 4 2 3 4}
385*c5c4113dSnw141292do_test view-9.6 {
386*c5c4113dSnw141292  execsql {
387*c5c4113dSnw141292    SELECT * FROM v10 ORDER BY 1;
388*c5c4113dSnw141292  }
389*c5c4113dSnw141292} {3 4 4 2 5 1}
390*c5c4113dSnw141292
391*c5c4113dSnw141292# Tables with columns having peculiar quoted names used in views
392*c5c4113dSnw141292# Ticket #756.
393*c5c4113dSnw141292#
394*c5c4113dSnw141292do_test view-10.1 {
395*c5c4113dSnw141292  execsql {
396*c5c4113dSnw141292    CREATE TABLE t3("9" integer, [4] text);
397*c5c4113dSnw141292    INSERT INTO t3 VALUES(1,2);
398*c5c4113dSnw141292    CREATE VIEW v_t3_a AS SELECT a.[9] FROM t3 AS a;
399*c5c4113dSnw141292    CREATE VIEW v_t3_b AS SELECT "4" FROM t3;
400*c5c4113dSnw141292    SELECT * FROM v_t3_a;
401*c5c4113dSnw141292  }
402*c5c4113dSnw141292} {1}
403*c5c4113dSnw141292do_test view-10.2 {
404*c5c4113dSnw141292  execsql {
405*c5c4113dSnw141292    SELECT * FROM v_t3_b;
406*c5c4113dSnw141292  }
407*c5c4113dSnw141292} {2}
408*c5c4113dSnw141292
409*c5c4113dSnw141292
410*c5c4113dSnw141292finish_test
411