1
votes

I have a DynamoDB table called Message with the following attributes:

  • message_id: number (partition key)
  • user_id: number (sort key)
  • incoming: boolean
  • subject: string

I want to create a global secondary index with user_id for the partition key, and the combined value of incoming and subject for the sort key.

Global secondary index:

  • user_id: partition key
  • incoming#subject: sort key

Do I have to manually cast the incoming attribute to a string (where true becomes "1", and false becomes "0") before combining it with subject? What is the standard way to handle such a scenario?

1

1 Answers

1
votes

As far as I know, I don't think that you can have different attributes like incoming#subject only in a global secondary index and separate incoming and subject attributes only in the original table. The attributes in your index will reflect the ones in the table. The difference between the two representations is that they have a different partition key and sort key. So, you can't "combine" incoming#subject just in the index without having this attribute in the table as well.

However, having incoming#subject in both the table and the index would solve your problem since its value would be determined outside of the database (when you write into the table). You should thus be able to "cast" it to whatever you want when you insert or update the data--whether it is true#my_subject_here or 1#another_subject.

Let me know if that works for you!