IF列有一个值

时间:2017-03-20 06:20:52

标签: sql postgresql

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

一样检查
object.y = 1
if object.y:
   <statements>

像这样我需要检查Postgres

这是我的疑问:

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

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

2 个答案:

答案 0 :(得分:0)

试试这个

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]))

答案 1 :(得分:0)

这是我已经解决的答案

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]))

参考:https://www.techonthenet.com/postgresql/is_not_null.php