Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id C079E632FCD for ; Sun, 30 Aug 2009 18:52:06 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 82184-05 for ; Sun, 30 Aug 2009 21:51:50 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from smtp28.orange.fr (smtp28.orange.fr [80.12.242.99]) by mail.postgresql.org (Postfix) with ESMTP id ECFBD63287A for ; Sun, 30 Aug 2009 18:51:55 -0300 (ADT) Received: from me-wanadoo.net (localhost [127.0.0.1]) by mwinf2801.orange.fr (SMTP Server) with ESMTP id B1DC180000A6; Sun, 30 Aug 2009 23:51:53 +0200 (CEST) Received: from me-wanadoo.net (localhost [127.0.0.1]) by mwinf2801.orange.fr (SMTP Server) with ESMTP id A601280000AC; Sun, 30 Aug 2009 23:51:53 +0200 (CEST) Received: from [10.129.36.10] (Mix-Rennes201-1-180.w193-250.abo.wanadoo.fr [193.250.26.180]) by mwinf2801.orange.fr (SMTP Server) with ESMTP id 2743480000A6; Sun, 30 Aug 2009 23:51:53 +0200 (CEST) X-ME-UUID: 20090830215153160.2743480000A6@mwinf2801.orange.fr Message-ID: <4A9AF477.5040706@wanadoo.fr> Date: Sun, 30 Aug 2009 23:51:51 +0200 From: Sylvain Leroux Organization: http://www.chicoree.fr User-Agent: Thunderbird 2.0.0.23 (Macintosh/20090812) MIME-Version: 1.0 To: pgsql-jdbc@postgresql.org CC: Damiano Bolzoni Subject: Re: Search content within a bytea field References: <6fb522db0908301333o3bfeb6e9l5c2ad9dd04308e18@mail.gmail.com> In-Reply-To: <6fb522db0908301333o3bfeb6e9l5c2ad9dd04308e18@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.001 tagged_above=-10 required=5 tests=BAYES_50=0.001 X-Spam-Level: X-Archive-Number: 200908/90 X-Sequence-Number: 19939 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