您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

在Select(PostgreSQL / pgAdmin)中将布尔值返回为TRUE或FALSE

在Select(PostgreSQL / pgAdmin)中将布尔值返回为TRUE或FALSE

如果您只想显示文字TRUEFALSE,则可以使用您提出的case语句。因为Postgresql对待TRUEtrueyesonyt1为真,我会控制我怎么会想输出的样子。

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 |
SQLServer 2022/1/1 18:37:06 有330人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶