DynamoDB GSI using boolean like a hash key

Viewed 1429

It's just a doubt that i cant find on the internet.
I have a table like this:

|  id | infos | ignored |
|  1  | abc  | true       |
|  2  | def   | false      |
|  3  | ghi   | false      |

I see i cant create a DynamoDB GSI on booleans columns. It's right?
I want to create a GSI on this ignored column.

1 Answers

The DynamoDB console only allows GSIs using types of string, binary, or number.

enter image description here

So you could use strings ("t" or "f"), numbers (1 or 0) or binary (also 1 or 0) to represent a boolean value if you'd like.

It sounds like you're trying to build a sparse index (e.g. only certain items are in the index). Keep in mind that you can do this by the mere existence of the attribute that makes up the GSI.

For example, you could include the ignored attribute on items you want to project into the index and remove the ignored attribute from items you do not want in the index.

Related