Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id CFF0A633610 for ; Mon, 31 Aug 2009 11:11:22 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 66197-07 for ; Mon, 31 Aug 2009 14:11:14 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id A664363329C for ; Mon, 31 Aug 2009 11:11:14 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id n7VEBBiS000799; Mon, 31 Aug 2009 10:11:11 -0400 (EDT) To: Damiano Bolzoni cc: Sylvain Leroux , pgsql-jdbc@postgresql.org Subject: Re: Search content within a bytea field In-reply-to: <6fb522db0908302306n7fcda5f7ncd7423f650855dca@mail.gmail.com> References: <6fb522db0908301333o3bfeb6e9l5c2ad9dd04308e18@mail.gmail.com> <4A9AF477.5040706@wanadoo.fr> <6fb522db0908302306n7fcda5f7ncd7423f650855dca@mail.gmail.com> Comments: In-reply-to Damiano Bolzoni message dated "Mon, 31 Aug 2009 08:06:36 +0200" Date: Mon, 31 Aug 2009 10:11:11 -0400 Message-ID: <798.1251727871@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.599 tagged_above=-10 required=5 tests=BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 200908/96 X-Sequence-Number: 19945 Damiano Bolzoni writes: > But...why if I manually query with a SQL client (AquaStudio) as > follows: > SELECT myfield FROM mytable WHERE myfield LIKE '%hello%' > and 'myfield' is a bytea field I get the result I expected? The unknown-type literal is assumed to be of type bytea in this case. In general, if the parser finds "known_type_value operator unmarked_literal" then it preferentially selects an operator with both input types the same, ie, it prefers to believe the unmarked_literal is the same data type as the other input. The JDBC environment behaves differently because setString and so on do not produce unmarked literals --- there's an implicit cast to some datatype. So you have to make sure you've picked a parameter-setting function that is reasonably compatible with the intended operation. This is a good thing, really; it tends to keep the system from choosing an unexpected operation. regards, tom lane