From: Sylvain Leroux <sl20@wanadoo.fr>
To: pgsql-jdbc@postgresql.org
Cc: Damiano Bolzoni <damiano.bolzoni@gmail.com>
Subject: Re: Search content within a bytea field
Date: Sun, 30 Aug 2009 23:51:51 +0200
Message-ID: <4A9AF477.5040706@wanadoo.fr> (raw)
In-Reply-To: <6fb522db0908301333o3bfeb6e9l5c2ad9dd04308e18@mail.gmail.com>
References: <6fb522db0908301333o3bfeb6e9l5c2ad9dd04308e18@mail.gmail.com>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: sl20@wanadoo.fr, damiano.bolzoni@gmail.com
Subject: Re: Search content within a bytea field
In-Reply-To: <4A9AF477.5040706@wanadoo.fr>
References: <6fb522db0908301333o3bfeb6e9l5c2ad9dd04308e18@mail.gmail.com> <4A9AF477.5040706@wanadoo.fr>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox