0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

DynamoDB@boto3のクエリの書き方メモ

Last updated at Posted at 2020-08-06

DynamoDBのクエリの書き方@boto3メモ。忘れがちなあなたに。

DynamoDBのテーブルの項目定義

パーティションキー:primary_id
ソートキー    :sort_id
属性1      :timestamp

コード

a = client.query(
    TableName='table-name',
    # Limit=500,
    KeyConditionExpression='primary_id = :id and begins_with(sort_id, :sort_id)', # 主キー向けのクエリ
    # FilterExpression='#tstamp > :st and #tstamp <= :ed', # 属性向けのクエリ
    # ExpressionAttributeNames={
    #     '#tstamp': 'timestamp' # timestampが予約語になっていて使えなので代替する
    # },
    ExpressionAttributeValues={
        ':id':{'S':'primary_001'},
        ':sort_id':{'S':f'sort_2020080101'},
        # ':st':{'N':'202008010000'},
        # ':ed':{'N':'202008010010'},
    },
    # ExclusiveStartKey={'primary_id': {'S': 'xxxx'}, 'sort_id': {'S': 'yyyy'}},
)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?