How to check if item is found in a list for the view's select statement?


I am following the example on views in Implementing Views in Java or Scala :: Kalix Documentation. I do have the get function that would need to check if item is in the list of the items. How do I have the query string to do something like:

query: “SELECT * FROM carts WHERE :item_id IN items”? Thank you for your help.

I think :item_id IN ANY(items) is what you are looking for, see query array operator docs here: Implementing Views :: Kalix Documentation

Thank you for your help, Johan. Let me try that out.

Yes, using = ANY(items) will check if an item is in the items array.

If your item is like the LineItem from the shopping cart samples:

message LineItem {
  string product_id = 1;
  string name = 2;
  int32 quantity = 3;

And you want to check if there’s an item with a particular product id, then use a query like this:

SELECT * FROM carts WHERE :product_id = ANY(items.product_id)