0

因此,我编写了一个 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 表单的下拉菜单中发送,因此它只能是“新”或“旧”。关于可能导致此问题的任何想法?

4

1 回答 1

1

Try something like:

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))
于 2013-08-08T08:35:52.357 回答