0

I've tested that select with PostgreSQL and it seems to work fine - return a list of items with resourceId mentioned in :resourceIdList (if any). If :resourceIdList is null - then return all of them.

select b.resourceid,
       b.datecreatedutc as basecreated,
       b.datedeletedutc as basedeleted
from productbasetable b
where b.datedeletedutc is null
  and case
          when :resourceIdList is not null
              then b.resourceid in :resourceIdList
          else true
    end;

The problem occurs when I'm trying to use it in SqlDelight: the generated code has a problem with when :resourceIdList is not null (encode fun expects a T type, not a List) enter image description here

Is there another way to check if :resourceIdList is null/empty before the IN statement?

P. Savrov
  • 1,064
  • 4
  • 17
  • 29
  • 1
    as to your SQL, you can simplify it to `where b.datedeletedutc is null and (:resourceIdList is not null or b.resourceid in :resourceIdList)`. But this won't solve the issue, it seems like a SQLDelight bug, I suggest you filling an issue or asking a question on [github](https://github.com/cashapp/sqldelight/issues/new/choose) – Phil Dukhov Aug 29 '21 at 15:05
  • @PhilipDukhov yeah, I've created an issue, but don't expect any solution soon. They have tons of them open :( it's here: https://github.com/AlecStrong/sql-psi/issues/285 – P. Savrov Aug 29 '21 at 17:02
  • 1
    Yep, some of them are mine as well :D The only solution I can think of at this point is to create two functions instead of one – Phil Dukhov Aug 29 '21 at 18:12

0 Answers0