PostgreSQL COALESCE 与 IN
PostgreSQL COALESCE with IN
我有以下使用 PostgreSQL 的示例语句:
SELECT ((? IS NULL) OR (1 IN ?))
在哪里?可以是 null
或 (1, 2, 3)
之类的东西。它显然适用于非空值,但会导致空值的语法错误。
我一直在尝试使用 COALESCE,但到目前为止没有任何运气或 Google 帮助。
如何正确编写上述语句来处理? = NULL
?
您可以使用 Postgres array
而不是列表,例如:
SELECT
coalesce(1 = any(null), true) a,
coalesce(1 = any(array[1,2,3]), true) b,
coalesce(1 = any('{1,2,3}'), true) c;
a | b | c
---+---+---
t | t | t
(1 row)
我有以下使用 PostgreSQL 的示例语句:
SELECT ((? IS NULL) OR (1 IN ?))
在哪里?可以是 null
或 (1, 2, 3)
之类的东西。它显然适用于非空值,但会导致空值的语法错误。
我一直在尝试使用 COALESCE,但到目前为止没有任何运气或 Google 帮助。
如何正确编写上述语句来处理? = NULL
?
您可以使用 Postgres array
而不是列表,例如:
SELECT
coalesce(1 = any(null), true) a,
coalesce(1 = any(array[1,2,3]), true) b,
coalesce(1 = any('{1,2,3}'), true) c;
a | b | c
---+---+---
t | t | t
(1 row)