Re: Re: [CLSQL-Help] inserting FALSE

John DeSoi <[email protected]> Thu, 11 May 2006 11:22:06 -0400
Newsgroups gmane.lisp.clsql.devel
Message-ID <[email protected]>
On May 11, 2006, at 10:30 AM, Kevin Rosenberg wrote:

> IIRC, postgresql acts like a CHAR(1) with storing 't' and 'f',
> but like MySQL, can use a boolean field (like active_row) in a  
> WHERE clause
> "SELECT rowid FROM FOO WHERE active_row"

PostgreSQL has a true boolean type using the symbols true and false.  
It will will cast the strings 't', 'f', 'true', 'false' to their  
corresponding boolean values, but anything else will result in an  
error. It will also cast zero and non-zero integer values to  
booleans. Examples below.



John DeSoi, Ph.D.
http://pgedit.com/
Power Tools for PostgreSQL



=== psql 9 ===
select 1 = 1;
?column?
----------
t
(1 row)


=== psql 10 ===
select (1 = 1) = t;
psql:4: ERROR:  column "t" does not exist

=== psql 11 ===
select (1 = 1) = true;
?column?
----------
t
(1 row)


=== psql 12 ===
select (1 = 1) = 't';
?column?
----------
t
(1 row)


=== psql 13 ===
select (1 = 1) = 'true';
?column?
----------
t
(1 row)


=== psql 14 ===
select (1 = 1) = '?';
psql:12: ERROR:  invalid input syntax for type boolean: "?"


=== psql 15 ===
select 0::boolean;
bool
------
f
(1 row)


=== psql 16 ===
select 1::boolean;
bool
------
t
(1 row)


=== psql 17 ===
select 10::boolean;
bool
------
t
(1 row)


=== psql 18 ===
select 10.5::boolean;
psql:20: ERROR:  cannot cast type numeric to boolean