如果您只想显示文字TRUE
或FALSE
,则可以使用您提出的case语句。因为Postgresql对待TRUE
,true
,yes
,on
,y
,t
和1
为真,我会控制我怎么会想输出的样子。
Where子句可以这样写:
select * from tablename where active
--or--
select * from tablename where active = true
(我的建议与Postgresql相同-使用true)
选择时,尽管可能会犹豫使用case语句,但我仍然建议您这样做以控制您的输出字符串文字。
您的查询如下所示:
select
case when active = TRUE then 'TRUE' else 'FALSE' end as active_status,
...other columns...
from tablename
where active = TRUE;
sqlfiddle示例:http://sqlfiddle.com/#!15/4764d/1
create table test (id int, fullname varchar(100), active boolean);
insert into test values (1, 'test1', FALSE), (2, 'test2', TRUE), (3, 'test3', TRUE);
select
id,
fullname,
case when active = TRUE then 'TRUE' else 'FALSE' end as active_status
from test;
| id | fullname | active_status |
|----|----------|---------------|
| 1 | test1 | FALSE |
| 2 | test2 | TRUE |
| 3 | test3 | TRUE |