Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to escape reserved keywords in DynamoDB ExecuteStatementRequest?

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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?

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading