-1
response = ddb.get_item(
TableName = table,
Key={
    'col_name': {'S': 'a'}
}
)

I understand that the above code will return items from the table in which the column contains 'a'. However, I am looking to query in such a way that if the column contains "I am good" and my search string is "am", I should be able to match the "am" in the text contained in the table and retrieve rows which contain such matches. Essentially, I am looking to match substrings instead of the actual strings. How do I go about this?

1 Answers1

0

I'd suggest using a different DB.

DDB doesn't work like an RDBMS or something like Open Search...

GetItem() requires the entire primary key.

  • If the table/GSI has just a partition (aka hash) key then you have to have the exact partition key value.
  • If you have a partition & sort key defined, you need the exact values for both.

Only with Query() can you do a match on a partial value using the BEGINS_WITH ComparisonOperator. (Note that CONTAINS is not supported for Query). Additionally, that matching is only for the sort key, you still have to pass the exact value of the partition key.

In SQL it would look like so

select * 
from table
where partitionKey = :hkvalue 
  and sortkey like (:skvalue concat '%')

Only a full table Scan() allows you to match using CONTAINS against some random attribute. It does so by reading the entire table 1MB at a time, which you pay for, and throwing about anything that doesn't match.

In general, if you need to use Scan() often, you're doing something wrong. Either with your design, or with the choice of DDB in the first place.

Charles
  • 21,637
  • 1
  • 20
  • 44