Question

I need to make a query based on a specific element of a bytea column in PostgreSQL. I tried the following query:

select * from my_table where bytea_column[4] between 160 and 183 limit 1

-but it gives me ERROR: cannot subscript type bytea because it is not an array.

Is there a way I can select a specific element of a bytea? I would like to avoid casting it to text and using like %%.

Was it helpful?

Solution

Use the get_byte function. This allows you to retrieve a single byte.

Alternatively you can use the substring function to retrieve a sequence of bytes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top