Re: Search content within a bytea field

Поиск
Список
Период
Сортировка
От Sylvain Leroux
Тема Re: Search content within a bytea field
Дата
Msg-id 4A9AF477.5040706@wanadoo.fr
обсуждение исходный текст
Ответ на Search content within a bytea field  (Damiano Bolzoni <damiano.bolzoni@gmail.com>)
Ответы Re: Search content within a bytea field
Re: Search content within a bytea field
Список 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 по дате отправления:

Предыдущее
От: Damiano Bolzoni
Дата:
Сообщение: Search content within a bytea field
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Search content within a bytea field