Creating an index with type casting

19 views
Skip to first unread message

Pablo Martinez

unread,
Apr 7, 2022, 6:46:06 PM4/7/22
to peewee-orm
Hey there! I've looked around online and haven't been able to find a solution, but apologies if this question has been asked before.

I am trying to create an index on a jsonb column similar to the raw query:
CREATE INDEX idx ON table((jb_column::text));

where jb_column is the jsonb field.

I'm running into issues applying the index using the model class. I've tried mytable.add_index(SQL(CREATE INDEX idx ...)). While this does create the desired index, when I try to reset my database using the built-in model.delete().execute() functionality it fails to delete this index.

Therefore, I've also tried creating the index using more built-in peewee functionality. I have attempted:

idx = (mytable.index(
           mytable.jb_column.cast('text')))
mytable.add_index(idx)

However, this does not create the desired index.  Any advice?

Thank you :)
Reply all
Reply to author
Forward
0 new messages