Re: Search content within a bytea field - Mailing list pgsql-jdbc

From Tom Lane
Subject Re: Search content within a bytea field
Date
Msg-id 798.1251727871@sss.pgh.pa.us
Whole thread Raw
In response to Re: Search content within a bytea field  (Damiano Bolzoni <damiano.bolzoni@gmail.com>)
Responses Re: Search content within a bytea field  (Florian Weimer <fweimer@bfk.de>)
List pgsql-jdbc
Damiano Bolzoni <damiano.bolzoni@gmail.com> 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

pgsql-jdbc by date:

Previous
From: dmp
Date:
Subject: Re: Search content within a bytea field
Next
From: Thomas Kellerer
Date:
Subject: Re: Search content within a bytea field