So I have written a postgreSQL function that is supposed to do a search on a table based on a huge amount of optional input parameters which i group with lots of AND statements. This one however:
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)
)
)
gives me a
ERROR: more than one row returned by a subquery used as an expression
This isnt helping much since I do want it to return a lot more than one row. The values of the newcheck variable will be sent from a dropdown menu in a web form so it can only be 'New' or 'Old'. Any ideas on what might be causing this problem?
CASEstatement expects one result in every branch.