所以我编写了一个postgreSQL函数,它应该根据大量的可选输入参数对表进行搜索,这些参数与很多AND语句组合在一起。但是这个:
AND
(
(newcheck IS NULL)
OR
(
newcheck IS NOT NULL AND product.id IN(
CASE WHEN newcheck='New'
THEN
(SELECT product.id FROM product WHERE product.anew IS true)
ELSE
(SELECT product.id from product WHERE product.anew IS false)
END)
)
)
给了我一个
ERROR: more than one row returned by a subquery used as an expression
这并没有多大帮助,因为我希望它能够返回多行。 newcheck变量的值将从Web表单的下拉菜单发送,因此它只能是“New”或“Old”。 关于可能导致这个问题的任何想法?
答案 0 :(得分:1)
尝试类似:
AND ((newcheck IS NULL)
OR (newcheck IS NOT NULL
AND product.id IN (SELECT product.id
FROM product
WHERE product.anew = CASE WHEN newcheck='New'
THEN true
ELSE false
END))