From: | Sylvain Leroux <sl20(at)wanadoo(dot)fr> |
---|---|
To: | pgsql-jdbc(at)postgresql(dot)org |
Cc: | Damiano Bolzoni <damiano(dot)bolzoni(at)gmail(dot)com> |
Subject: | Re: Search content within a bytea field |
Date: | 2009-08-30 21:51:51 |
Message-ID: | 4A9AF477.5040706@wanadoo.fr |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2009-08-30 22:58:49 | Re: Search content within a bytea field |
Previous Message | Damiano Bolzoni | 2009-08-30 20:33:00 | Search content within a bytea field |