Skip to content

DynamoDB: table name can't be surround by single quotation marks #25

@khanh-alice

Description

@khanh-alice

Unsure if it's used to work or intended, but I notice that moto allows DynamoDB's table name to be surround by single quotation marks. This is not the case on an real DynamoDB.

Given main.py

import boto3


def execute_statement():
    client = boto3.client("dynamodb", region_name="us-east-1")

    table_name = "testtable"
    response = client.execute_statement(Statement=f"select pk from '{table_name}'")

    items = response.get("Items")
    print(items)


if __name__ == "__main__":
    execute_statement()

and main_test.py

import boto3
from moto import mock_aws


@mock_aws
def test_main():
    client = boto3.client("dynamodb", region_name="us-east-1")
    table_name = "testtable"

    client.create_table(
        TableName=table_name,
        KeySchema=[
            {"AttributeName": "pk", "KeyType": "HASH"},
        ],
        AttributeDefinitions=[
            {"AttributeName": "pk", "AttributeType": "S"},
        ],
        BillingMode="PAY_PER_REQUEST",
    )
    client.put_item(
        TableName=table_name,
        Item={
            "pk": {"S": "1"},
        },
    )

    from main import execute_statement
    execute_statement()

Running main.py return this error

Traceback (most recent call last):
  File "/Users/khanh.le/Git/mototest/main.py", line 15, in <module>
    execute_statement()
  File "/Users/khanh.le/Git/mototest/main.py", line 8, in execute_statement
    response = client.execute_statement(Statement=f"select pk from '{table_name}'")
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/khanh.le/Git/mototest/.venv/lib/python3.12/site-packages/botocore/client.py", line 569, in _api_call
    return self._make_api_call(operation_name, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/khanh.le/Git/mototest/.venv/lib/python3.12/site-packages/botocore/client.py", line 1023, in _make_api_call
    raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (ValidationException) when calling the ExecuteStatement operation: Unexpected from source

But running moto_test.py returns a successful test.

A quick check on PartiQL Editor on AWS console also shows some kind of errors when I try surround the table name with single quotation mark.

SELECT
image

UPDATE
image

DELETE
image

INSERT
image

boto3==1.35.29
botocore==1.35.29
moto==5.0.16
py-partiql-parser==0.5.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions