0

There is postgres sql query, shown below:

Select agencyId, SUM(open),
   from agencies 
   where agency_id= 100 and agency_platform = any(@platformIds) 
   GROUP BY agencyId;

If platformIds list is empty then this query doesn't return any data, and on the other hand below query data with no issues:

Select agencyId, SUM(open), 
    from agencies 
    where agency_id= 100 
    GROUP BY agencyId;

any thoughts?

3
  • 1
    It’s behaving as designed - the any check returns false. Perhaps add a condition to only check the platformIds if there are any? Commented Jan 27, 2023 at 18:29
  • @stuartd, I have tried this Select agencyId, SUM(open) from agencies where agency_id= 100 and case when array_length(@platformIds, 1) > 0 then agency_platform = any(@platformIds) else true end GROUP BY agencyId; but it says ERROR: syntax error at or near "array_length". Any clue? Commented Jan 27, 2023 at 18:33
  • stackoverflow.com/questions/11188756/… Commented Jan 27, 2023 at 18:35

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.