我需要编写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是否有值。
答案 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]))