I need to match a binary column with its beginning.
For text columns it's easy: LIKE 'image/%'
. This uses BTREE index if any.
Is it possible to do this also using an index for a binary column?
BTW, I store UTF-8 encoded strings in Binary, because there is no hard standard that all of them are UTF-8. So, I store a binary representation (maybe even with \0 (zero) bytes), as I cannot use UTF-8.
text
value, the apply the LIKE condition on that.convert_from(... , 'UTF-8')
then it could be like this:WHERE convert_from(... , 'UTF-8') like '...'
LIKE
operator with bytea arguments works out of the box. That includes using a btree index for prefix matching if available. Just create your index and confirm withEXPLAIN
that it's being used.