Sql 如果列有一个值

Sql 如果列有一个值,sql,postgresql,Sql,Postgresql,我需要编写sql查询来检查表x中的列y是否有值。在python中,我可以这样检查 object.y = 1 if object.y: <statements> object.y=1 如果object.y: 像这样,我需要报考博士后 这是我的疑问: request.cr.execute(““从x中选择*,其中父项id=%s和nav_include=true,网站发布=true,cms_lang=NULL,y为true,按顺序排列)”,([事件根]) 这里我需要检查y是否有一个

我需要编写sql查询来检查表x中的列y是否有值。在python中,我可以这样检查

object.y = 1
if object.y:
   <statements>
object.y=1
如果object.y:
像这样,我需要报考博士后

这是我的疑问:

request.cr.execute(““从x中选择*,其中父项id=%s和nav_include=true,网站发布=true,cms_lang=NULL,y为true,按顺序排列)”,([事件根])

这里我需要检查y是否有一个值。

试试这个

request.cr.execute(""" select * from x where parent_id = %s and nav_include = true and website_published = true and cms_lang = NULL and coalesce(y, FALSE) is TRUE order by sequence""",([event_root]))

这是我的答案

request.cr.execute(""" select * from x where parent_id = %s and nav_include = true and website_published = true and cms_lang is NULL and y is not null order by sequence""",([event_root]))

参考:

您可以在where子句
中使用coalesce函数,y为TRUE
已经在检查“y是否有值”。该条件将永远不会返回y没有值的行(“为空”)。是的,这里的事实是y不是布尔字段,因此我无法检查是否为真@a_horse_with_no_name然后使用
y is not null
是的您是对的@a_horse_with_no_name事件\u rel是一个整数字段@vecchiasinora
cms_lang=null
将永远不会返回任何内容