有什么方法可以在 Sql Server 和 PostgreSQL 上执行“where booleanvalue=false”吗?

2024-03-24

我正在尝试使应用程序能够在 Sql Server 和 PostgreSQL 上运行。

我似乎找不到一个通用的表达方式,基本上是

 select * from table where booleancol=false

在 SQL Server 上我必须这样做(这非常令人困惑,因为位类型的默认值必须是 true 或 false,但你不能将它们分配给 true 或 false 或对其进行测试)

select * from table where booleancol=0

在 PostgreSQL 上我必须做

select * from table where booleancol is false

我们的程序中有很多查询可以执行此操作,因此我更愿意使用一些通用语法而不是这样做if(dbformat=="postgres")..类型废话..

另外,我更愿意将列保留为布尔/位类型,而不是将它们更改为整数类型..尽管这是一个选项..


抱歉,这部分内容根本不正确;不到一半真实;-)

在 PostgreSQL 上我必须做

select * from table where booleancol is false

事实上,以下所有语法在 PostgreSQL 中都是有效的:

select * from table where not booleancol
select * from table where booleancol = 'f'
select * from table where booleancol = 'false'
select * from table where booleancol = 'n'
select * from table where booleancol is false
select * from table where booleancol is not true
select * from table where booleancol = false
select * from table where booleancol <> true
select * from table where booleancol != true
select * from table where booleancol <> 'TRUE'

这是 postgres 灵活语法的示例,它使得从其他数据库移植应用程序变得非常容易。

See the docs http://www.postgresql.org/docs/8.4/static/datatype-boolean.html.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

有什么方法可以在 Sql Server 和 PostgreSQL 上执行“where booleanvalue=false”吗? 的相关文章

随机推荐