How to use IN statement in partiqL DynamodB

2.2k views Asked by At

I want to convert this query select lKey from KeyMapping where gKey in ['A#1','A#2','A#3'];

I have a List that contain A#1, A#2 and A#3

into Java code to extract records from DynamoDB using PartiQL

1

There are 1 answers

0
Sunil Kr Yadav On BEST ANSWER
@Autowired
private AmazonDynamoDB client;


List<String> paramList = new ArrayList<>(); //List of Parameters
paramList.add("A#1");
paramList.add("A#2");
paramList.add("A#3");

ExecuteStatementRequest request = new ExecuteStatementRequest();
String[] placeholders = new String[paramList.size()];
Arrays.fill(placeholders, "?");
String commalist = Arrays.stream(placeholders).collect(Collectors.joining(","));
        request.setStatement("select * from "+appConfigs.getBoclipsTableName()+" where id in ("+commalist+")");

List<AttributeValue> parameters = new ArrayList<>();
for(String videoId: videoIds){
    parameters.add(new AttributeValue(videoId));
}
System.out.println(client.executeStatement(request).toString());