5 -- sanity check - if this fails go insane!
13 -- ******************testing built-in type bool********************
14 -- check bool input syntax
21 SELECT false AS false;
27 SELECT bool 't' AS true;
33 SELECT bool ' f ' AS false;
39 SELECT bool 'true' AS true;
45 SELECT bool 'test' AS error;
46 ERROR: invalid input syntax for type boolean: "test"
47 LINE 1: SELECT bool 'test' AS error;
49 SELECT bool 'false' AS false;
55 SELECT bool 'foo' AS error;
56 ERROR: invalid input syntax for type boolean: "foo"
57 LINE 1: SELECT bool 'foo' AS error;
59 SELECT bool 'y' AS true;
65 SELECT bool 'yes' AS true;
71 SELECT bool 'yeah' AS error;
72 ERROR: invalid input syntax for type boolean: "yeah"
73 LINE 1: SELECT bool 'yeah' AS error;
75 SELECT bool 'n' AS false;
81 SELECT bool 'no' AS false;
87 SELECT bool 'nay' AS error;
88 ERROR: invalid input syntax for type boolean: "nay"
89 LINE 1: SELECT bool 'nay' AS error;
91 SELECT bool 'on' AS true;
97 SELECT bool 'off' AS false;
103 SELECT bool 'of' AS false;
109 SELECT bool 'o' AS error;
110 ERROR: invalid input syntax for type boolean: "o"
111 LINE 1: SELECT bool 'o' AS error;
113 SELECT bool 'on_' AS error;
114 ERROR: invalid input syntax for type boolean: "on_"
115 LINE 1: SELECT bool 'on_' AS error;
117 SELECT bool 'off_' AS error;
118 ERROR: invalid input syntax for type boolean: "off_"
119 LINE 1: SELECT bool 'off_' AS error;
121 SELECT bool '1' AS true;
127 SELECT bool '11' AS error;
128 ERROR: invalid input syntax for type boolean: "11"
129 LINE 1: SELECT bool '11' AS error;
131 SELECT bool '0' AS false;
137 SELECT bool '000' AS error;
138 ERROR: invalid input syntax for type boolean: "000"
139 LINE 1: SELECT bool '000' AS error;
141 SELECT bool '' AS error;
142 ERROR: invalid input syntax for type boolean: ""
143 LINE 1: SELECT bool '' AS error;
145 -- and, or, not in qualifications
146 SELECT bool 't' or bool 'f' AS true;
152 SELECT bool 't' and bool 'f' AS false;
158 SELECT not bool 'f' AS true;
164 SELECT bool 't' = bool 'f' AS false;
170 SELECT bool 't' <> bool 'f' AS true;
176 SELECT bool 't' > bool 'f' AS true;
182 SELECT bool 't' >= bool 'f' AS true;
188 SELECT bool 'f' < bool 't' AS true;
194 SELECT bool 'f' <= bool 't' AS true;
200 -- explicit casts to/from text
201 SELECT 'TrUe'::text::boolean AS true, 'fAlse'::text::boolean AS false;
207 SELECT ' true '::text::boolean AS true,
208 ' FALSE'::text::boolean AS false;
214 SELECT true::boolean::text AS true, false::boolean::text AS false;
220 SELECT ' tru e '::text::boolean AS invalid; -- error
221 ERROR: invalid input syntax for type boolean: " tru e "
222 SELECT ''::text::boolean AS invalid; -- error
223 ERROR: invalid input syntax for type boolean: ""
224 CREATE TABLE BOOLTBL1 (f1 bool);
225 INSERT INTO BOOLTBL1 (f1) VALUES (bool 't');
226 INSERT INTO BOOLTBL1 (f1) VALUES (bool 'True');
227 INSERT INTO BOOLTBL1 (f1) VALUES (bool 'true');
228 -- BOOLTBL1 should be full of true's at this point
229 SELECT BOOLTBL1.* FROM BOOLTBL1;
239 WHERE f1 = bool 'true';
249 WHERE f1 <> bool 'false';
259 WHERE booleq(bool 'false', f1);
264 INSERT INTO BOOLTBL1 (f1) VALUES (bool 'f');
267 WHERE f1 = bool 'false';
273 CREATE TABLE BOOLTBL2 (f1 bool);
274 INSERT INTO BOOLTBL2 (f1) VALUES (bool 'f');
275 INSERT INTO BOOLTBL2 (f1) VALUES (bool 'false');
276 INSERT INTO BOOLTBL2 (f1) VALUES (bool 'False');
277 INSERT INTO BOOLTBL2 (f1) VALUES (bool 'FALSE');
278 -- This is now an invalid expression
279 -- For pre-v6.3 this evaluated to false - thomas 1997-10-23
280 INSERT INTO BOOLTBL2 (f1)
282 ERROR: invalid input syntax for type boolean: "XXX"
283 LINE 2: VALUES (bool 'XXX');
285 -- BOOLTBL2 should be full of false's at this point
286 SELECT BOOLTBL2.* FROM BOOLTBL2;
295 SELECT BOOLTBL1.*, BOOLTBL2.*
296 FROM BOOLTBL1, BOOLTBL2
297 WHERE BOOLTBL2.f1 <> BOOLTBL1.f1;
314 SELECT BOOLTBL1.*, BOOLTBL2.*
315 FROM BOOLTBL1, BOOLTBL2
316 WHERE boolne(BOOLTBL2.f1,BOOLTBL1.f1);
333 SELECT BOOLTBL1.*, BOOLTBL2.*
334 FROM BOOLTBL1, BOOLTBL2
335 WHERE BOOLTBL2.f1 = BOOLTBL1.f1 and BOOLTBL1.f1 = bool 'false';
344 SELECT BOOLTBL1.*, BOOLTBL2.*
345 FROM BOOLTBL1, BOOLTBL2
346 WHERE BOOLTBL2.f1 = BOOLTBL1.f1 or BOOLTBL1.f1 = bool 'true'
347 ORDER BY BOOLTBL1.f1, BOOLTBL2.f1;
370 -- Try all combinations to ensure that we get nothing when we expect nothing
371 -- - thomas 2000-01-04
385 WHERE f1 IS NOT FALSE;
403 WHERE f1 IS NOT TRUE;
418 WHERE f1 IS NOT FALSE;
436 WHERE f1 IS NOT TRUE;
446 -- Tests for BooleanTest
448 CREATE TABLE BOOLTBL3 (d text, b bool, o int);
449 INSERT INTO BOOLTBL3 (d, b, o) VALUES ('true', true, 1);
450 INSERT INTO BOOLTBL3 (d, b, o) VALUES ('false', false, 2);
451 INSERT INTO BOOLTBL3 (d, b, o) VALUES ('null', null, 3);
455 b IS NOT TRUE AS isnottrue,
456 b IS FALSE AS isfalse,
457 b IS NOT FALSE AS isnotfalse,
458 b IS UNKNOWN AS isunknown,
459 b IS NOT UNKNOWN AS isnotunknown
460 FROM booltbl3 ORDER BY o;
461 d | istrue | isnottrue | isfalse | isnotfalse | isunknown | isnotunknown
462 -------+--------+-----------+---------+------------+-----------+--------------
463 true | t | f | f | t | f | t
464 false | f | t | t | f | f | t
465 null | f | t | f | t | t | f
468 -- Test to make sure short-circuiting and NULL handling is
469 -- correct. Use a table as source to prevent constant simplification
471 CREATE TABLE booltbl4(isfalse bool, istrue bool, isnul bool);
472 INSERT INTO booltbl4 VALUES (false, true, null);
474 -- AND expression need to return null if there's any nulls and not all
475 -- of the value are true
476 SELECT istrue AND isnul AND istrue FROM booltbl4;
482 SELECT istrue AND istrue AND isnul FROM booltbl4;
488 SELECT isnul AND istrue AND istrue FROM booltbl4;
494 SELECT isfalse AND isnul AND istrue FROM booltbl4;
500 SELECT istrue AND isfalse AND isnul FROM booltbl4;
506 SELECT isnul AND istrue AND isfalse FROM booltbl4;
512 -- OR expression need to return null if there's any nulls and none
513 -- of the value is true
514 SELECT isfalse OR isnul OR isfalse FROM booltbl4;
520 SELECT isfalse OR isfalse OR isnul FROM booltbl4;
526 SELECT isnul OR isfalse OR isfalse FROM booltbl4;
532 SELECT isfalse OR isnul OR istrue FROM booltbl4;
538 SELECT istrue OR isfalse OR isnul FROM booltbl4;
544 SELECT isnul OR istrue OR isfalse FROM booltbl4;
552 -- Many tables are retained by the regression test, but these do not seem
553 -- particularly useful so just get rid of them for now.
554 -- - thomas 1997-11-30