如何将 ProjectExpression 与带空格的列名一起使用?
How to use ProjectExpression with column names with spaces?
我拒绝了,创建了一个大的 table,其中在列的名称中包含了 space。我正在尝试扫描此 table 和 select 特定信息。
import boto3
from boto3.dynamodb.conditions import Key
dynamodb = boto3.resource('dynamodb',
region_name='xx-xxxx-xx')
table = dynamodb.Table('ourtable')
scan_kwargs = {
'FilterExpression': Key('primarykey').between(*key_range)
'ProjectionExpression': "primarykey, other column"
}
done = False
start_key = None
while not done:
if start_key:
scan_kwargs['ExclusiveStartKey'] = start_key
response = table.scan(**scan_kwargs)
start_key = response.get('LastEvaluatedKey', None)
done = start_key is None
运行 这给了我这个错误:
An error occurred (ValidationException) when calling the Scan operation: Invalid ProjectionExpression: Syntax error; token: "column", near: "other column"
我假设这是一些解析问题。我尝试了几种转义 space 的方法,但都无济于事。这些尝试包括:
{other column}
\'other column\'
\"other column\"
other%20column
other\column
other{BEASPACE}column
我不想重拍这个 table。提前感谢您的帮助。
在 DynamoDB 表达式中,不是像您尝试的那样用引号或反斜杠“转义”列名,您需要做的是对附加 references 中列出的名称使用 references =11=]参数。例如,
scan_kwargs = {
'FilterExpression': Key('primarykey').between(*key_range)
'ProjectionExpression': "primarykey, #othercolumn"
'ExpressionAttributeNames': {'#othercolumn': 'other column'}
}
请注意在投影表达式中我如何使用 reference #othercolumn
而不是列的真实名称,然后定义该真实名称(可能包含空格或其他ExpressionAttributeNames
.
中的特殊字符)
我拒绝了,创建了一个大的 table,其中在列的名称中包含了 space。我正在尝试扫描此 table 和 select 特定信息。
import boto3
from boto3.dynamodb.conditions import Key
dynamodb = boto3.resource('dynamodb',
region_name='xx-xxxx-xx')
table = dynamodb.Table('ourtable')
scan_kwargs = {
'FilterExpression': Key('primarykey').between(*key_range)
'ProjectionExpression': "primarykey, other column"
}
done = False
start_key = None
while not done:
if start_key:
scan_kwargs['ExclusiveStartKey'] = start_key
response = table.scan(**scan_kwargs)
start_key = response.get('LastEvaluatedKey', None)
done = start_key is None
运行 这给了我这个错误:
An error occurred (ValidationException) when calling the Scan operation: Invalid ProjectionExpression: Syntax error; token: "column", near: "other column"
我假设这是一些解析问题。我尝试了几种转义 space 的方法,但都无济于事。这些尝试包括:
{other column}
\'other column\'
\"other column\"
other%20column
other\column
other{BEASPACE}column
我不想重拍这个 table。提前感谢您的帮助。
在 DynamoDB 表达式中,不是像您尝试的那样用引号或反斜杠“转义”列名,您需要做的是对附加 references 中列出的名称使用 references =11=]参数。例如,
scan_kwargs = {
'FilterExpression': Key('primarykey').between(*key_range)
'ProjectionExpression': "primarykey, #othercolumn"
'ExpressionAttributeNames': {'#othercolumn': 'other column'}
}
请注意在投影表达式中我如何使用 reference #othercolumn
而不是列的真实名称,然后定义该真实名称(可能包含空格或其他ExpressionAttributeNames
.