How to implement `&&` (overlap) operator of postgres in DynamoDB?

Viewed 51

How to implement && (overlap) operator of postgres in DynamoDB?

Like postgres behaves -

select array[1, 2, 3] && array[2, 3];
-> true

select array[1, 2, 3] && array[3, 4];
-> true

select array[1, 2, 3] && array[4, 5];
-> false
1 Answers

I found a solution to achieve the above scenario. It may not be a good solution so open to your opinions and answers.

I used contains with or of DynamoDB to reach the desired results as follows.

field -> #arrayOfElements
values -> :elementToMatch (String)

contains(#arrayOfElements, :elementToMatch1) or contains(#arrayOfElements, :elementToMatch2)

Ex-

-- select array[1, 2, 3] && array[2, 3];
contains([1, 2, 3], 2) or contains([1, 2, 3], 3) -- raw example query
Related