Home > front end >  How to escape reserved keywords in DynamoDB ExecuteStatementRequest?
How to escape reserved keywords in DynamoDB ExecuteStatementRequest?

Time:01-23

I'm trying to issue an update ExecuteStatementRequest using DynamoDB and Java SDK 2.0. I'm struggling to escape keywords that are columns in my table schema.

The following statement:

var response = client.executeStatement(ExecuteStatementRequest.builder()
                .statement("""
                    UPDATE "my-table"
                    SET value=12.5
                    WHERE assignmentId='item1#123#item2#456#item3#789'
                    RETURNING ALL NEW *
                    """)
                .build());

When I run the following statement (notice that value column is a reserved keyword) I get the following error:

Exception in thread "main" software.amazon.awssdk.services.dynamodb.model.DynamoDbException: Statement wasn't well formed, can't be processed: Expected identifier for simple path (Service: DynamoDb, Status Code: 400, Request ID: XXX)

If instead of value I change the column name to val, the statement works fine. I know that in UdateItem operations I can pass in an array of expressionAttributeNames to replace keywords with aliases. Is there a similar primitive I can use for ExecuteStatementRequest?

CodePudding user response:

The documentation you link explicitly says what you need to do:

You can use a reserved keyword as a quoted identifier with double quotation marks (for example, "user").

That is the SQL standard way of escaping reserved words. In other words, use "value" (or possibly "VALUE") in your statement instead of value.

  • Related