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 -- Also try it with non-error-throwing API
146 SELECT pg_input_is_valid('true', 'bool');
152 SELECT pg_input_is_valid('asdf', 'bool');
158 SELECT * FROM pg_input_error_info('junk', 'bool');
159 message | detail | hint | sql_error_code
160 -----------------------------------------------+--------+------+----------------
161 invalid input syntax for type boolean: "junk" | | | 22P02
164 -- and, or, not in qualifications
165 SELECT bool 't' or bool 'f' AS true;
171 SELECT bool 't' and bool 'f' AS false;
177 SELECT not bool 'f' AS true;
183 SELECT bool 't' = bool 'f' AS false;
189 SELECT bool 't' <> bool 'f' AS true;
195 SELECT bool 't' > bool 'f' AS true;
201 SELECT bool 't' >= bool 'f' AS true;
207 SELECT bool 'f' < bool 't' AS true;
213 SELECT bool 'f' <= bool 't' AS true;
219 -- explicit casts to/from text
220 SELECT 'TrUe'::text::boolean AS true, 'fAlse'::text::boolean AS false;
226 SELECT ' true '::text::boolean AS true,
227 ' FALSE'::text::boolean AS false;
233 SELECT true::boolean::text AS true, false::boolean::text AS false;
239 SELECT ' tru e '::text::boolean AS invalid; -- error
240 ERROR: invalid input syntax for type boolean: " tru e "
241 SELECT ''::text::boolean AS invalid; -- error
242 ERROR: invalid input syntax for type boolean: ""
243 CREATE TABLE BOOLTBL1 (f1 bool);
244 INSERT INTO BOOLTBL1 (f1) VALUES (bool 't');
245 INSERT INTO BOOLTBL1 (f1) VALUES (bool 'True');
246 INSERT INTO BOOLTBL1 (f1) VALUES (bool 'true');
247 -- BOOLTBL1 should be full of true's at this point
248 SELECT BOOLTBL1.* FROM BOOLTBL1;
258 WHERE f1 = bool 'true';
268 WHERE f1 <> bool 'false';
278 WHERE booleq(bool 'false', f1);
283 INSERT INTO BOOLTBL1 (f1) VALUES (bool 'f');
286 WHERE f1 = bool 'false';
292 CREATE TABLE BOOLTBL2 (f1 bool);
293 INSERT INTO BOOLTBL2 (f1) VALUES (bool 'f');
294 INSERT INTO BOOLTBL2 (f1) VALUES (bool 'false');
295 INSERT INTO BOOLTBL2 (f1) VALUES (bool 'False');
296 INSERT INTO BOOLTBL2 (f1) VALUES (bool 'FALSE');
297 -- This is now an invalid expression
298 -- For pre-v6.3 this evaluated to false - thomas 1997-10-23
299 INSERT INTO BOOLTBL2 (f1)
301 ERROR: invalid input syntax for type boolean: "XXX"
302 LINE 2: VALUES (bool 'XXX');
304 -- BOOLTBL2 should be full of false's at this point
305 SELECT BOOLTBL2.* FROM BOOLTBL2;
314 SELECT BOOLTBL1.*, BOOLTBL2.*
315 FROM BOOLTBL1, BOOLTBL2
316 WHERE BOOLTBL2.f1 <> BOOLTBL1.f1;
333 SELECT BOOLTBL1.*, BOOLTBL2.*
334 FROM BOOLTBL1, BOOLTBL2
335 WHERE boolne(BOOLTBL2.f1,BOOLTBL1.f1);
352 SELECT BOOLTBL1.*, BOOLTBL2.*
353 FROM BOOLTBL1, BOOLTBL2
354 WHERE BOOLTBL2.f1 = BOOLTBL1.f1 and BOOLTBL1.f1 = bool 'false';
363 SELECT BOOLTBL1.*, BOOLTBL2.*
364 FROM BOOLTBL1, BOOLTBL2
365 WHERE BOOLTBL2.f1 = BOOLTBL1.f1 or BOOLTBL1.f1 = bool 'true'
366 ORDER BY BOOLTBL1.f1, BOOLTBL2.f1;
389 -- Try all combinations to ensure that we get nothing when we expect nothing
390 -- - thomas 2000-01-04
404 WHERE f1 IS NOT FALSE;
422 WHERE f1 IS NOT TRUE;
437 WHERE f1 IS NOT FALSE;
455 WHERE f1 IS NOT TRUE;
465 -- Tests for BooleanTest
467 CREATE TABLE BOOLTBL3 (d text, b bool, o int);
468 INSERT INTO BOOLTBL3 (d, b, o) VALUES ('true', true, 1);
469 INSERT INTO BOOLTBL3 (d, b, o) VALUES ('false', false, 2);
470 INSERT INTO BOOLTBL3 (d, b, o) VALUES ('null', null, 3);
474 b IS NOT TRUE AS isnottrue,
475 b IS FALSE AS isfalse,
476 b IS NOT FALSE AS isnotfalse,
477 b IS UNKNOWN AS isunknown,
478 b IS NOT UNKNOWN AS isnotunknown
479 FROM booltbl3 ORDER BY o;
480 d | istrue | isnottrue | isfalse | isnotfalse | isunknown | isnotunknown
481 -------+--------+-----------+---------+------------+-----------+--------------
482 true | t | f | f | t | f | t
483 false | f | t | t | f | f | t
484 null | f | t | f | t | t | f
487 -- Test to make sure short-circuiting and NULL handling is
488 -- correct. Use a table as source to prevent constant simplification
490 CREATE TABLE booltbl4(isfalse bool, istrue bool, isnul bool);
491 INSERT INTO booltbl4 VALUES (false, true, null);
493 -- AND expression need to return null if there's any nulls and not all
494 -- of the value are true
495 SELECT istrue AND isnul AND istrue FROM booltbl4;
501 SELECT istrue AND istrue AND isnul FROM booltbl4;
507 SELECT isnul AND istrue AND istrue FROM booltbl4;
513 SELECT isfalse AND isnul AND istrue FROM booltbl4;
519 SELECT istrue AND isfalse AND isnul FROM booltbl4;
525 SELECT isnul AND istrue AND isfalse FROM booltbl4;
531 -- OR expression need to return null if there's any nulls and none
532 -- of the value is true
533 SELECT isfalse OR isnul OR isfalse FROM booltbl4;
539 SELECT isfalse OR isfalse OR isnul FROM booltbl4;
545 SELECT isnul OR isfalse OR isfalse FROM booltbl4;
551 SELECT isfalse OR isnul OR istrue FROM booltbl4;
557 SELECT istrue OR isfalse OR isnul FROM booltbl4;
563 SELECT isnul OR istrue OR isfalse FROM booltbl4;
590 -- Many tables are retained by the regression test, but these do not seem
591 -- particularly useful so just get rid of them for now.
592 -- - thomas 1997-11-30