Re: Search content within a bytea field - Mailing list pgsql-jdbc

From Sylvain Leroux
Subject Re: Search content within a bytea field
Date
Msg-id 4A9AF477.5040706@wanadoo.fr
Whole thread Raw
In response to Search content within a bytea field  (Damiano Bolzoni <damiano.bolzoni@gmail.com>)
Responses Re: Search content within a bytea field
Re: Search content within a bytea field
List pgsql-jdbc
Hi Damiano,


It seems to me that the problem is comming from the BYTEA type, not from
the prepared statement by itself: As far as I know the only operator
supported by BYTEA is concatenation. You can't even compare two BYTEA
for (in)equality - even less using the LIKE operator.

However, you can convert BYTEA to an other type using CAST(). Something
like that might do the trick (I think):

SELECT id FROM mytable WHERE CAST(myfield AS TEXT) LIKE ?

Be warned that performances (and possibly memory consummation) of such a
request is certainly far from ideal!


Hope this helps,
Sylvain.

> Hi all,
> I'm trying to search for some content within a bytea field. My
> PreparedStatement looks like this:
>
> SELECT id FROM mytable WHERE myfield LIKE ?
>
> Now, when I execute a
>
> ps.setString(1, "%" + value + "%")
>
> where 'value' is the value I want to search for, the PS becomes
>
> SELECT id FROM mytable WHERE myfield LIKE %VALUE%
>
> and the query clearly fails ("operator does not exist: bytea ~~
> character varying"). Now, my question is....why? What am I doing
> wrong?
>
> Thanks for you help!
>


--
Website: http://www.chicoree.fr



pgsql-jdbc by date:

Previous
From: Damiano Bolzoni
Date:
Subject: Search content within a bytea field
Next
From: Tom Lane
Date:
Subject: Re: Search content within a bytea field