postgresql变量null或null语法错误

发布于 2025-02-09 20:54:09 字数 421 浏览 0 评论 0原文

我使用psycopg2,并且输入变化具有看起来像这样的条件:

WHERE %(variable)s is null or some_column in %(variable)s

问题是,当变量为null时,我会得到语法错误:

psycopg2.errors.SyntaxError: syntax error at or near "NULL"`
(NULL is null or (some_column IN NULL)) and
                                 ^

当然,该条件不应由于null为null已经是正确的,但是语法不通过。无论如何要解决此问题而不创建额外的变量?

I use psycopg2 and have input varaiables with a where condition that looks like this:

WHERE %(variable)s is null or some_column in %(variable)s

The problem is that when variable is null I get a syntax error:

psycopg2.errors.SyntaxError: syntax error at or near "NULL"`
(NULL is null or (some_column IN NULL)) and
                                 ^

That condition should of course not be evaluated since null is null is true already, but the syntax does not pass. Anyway to fix this without creating an extra variable?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文