I am trying to use query with KeyConditionExpression in Boto3 to query a DynamoDB table.
I am trying to return all the records using the following sudo expression
(PK=X AND SK=Y) OR (PK=A AND SK=B)
OR
KeyConditionExpression=((Key("PK").eq(f"USERID#{user_id}") & Key("SK").eq(f"PROJECTID#{project_id}")) | (Key("PK").eq(f"USERID#{user_id}PROJECTID#{project_id}") & Key("SK").begins_with("LAYERID#")))
PK is the primary key and SK is the Sort Key. Does this need to be 2 separate queries and the results join or can it be done in one?
Given that you know the complete key for each item, you don't need to use query.
You can issue two get_item calls or a single batch_get_item call.