Re: MySQL search query is not executing in Postgres DB

From: Craig Ringer <ringerc(at)ringerc(dot)id(dot)au>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Greg Stark <stark(at)mit(dot)edu>, Bruce Momjian <bruce(at)momjian(dot)us>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com>, premanand <kottiprem(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: MySQL search query is not executing in Postgres DB
Date: 2012-08-29 01:46:00
Message-ID: 503D7458.3000203@ringerc.id.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 08/29/2012 01:32 AM, Robert Haas wrote:
> On Tue, Aug 28, 2012 at 1:06 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>> Also, right at the moment it's not clear to me whether there are any
>> other cases besides integer literal vs smallint argument. I think
>> that's the only particularly surprising case within the numeric
>> hierarchy --- and for non-numeric types, the literal is generally going
>> to start out "unknown" so the whole problem doesn't arise. I feel
>> uncomfortable trying to invent general-purpose solutions to problems
>> we have only one instance of ...
>
> The other case that comes up regularly is someone trying to pass some
> kind of number to a function such as LPAD(). There is only one LPAD()
> so no ambiguity exists, but PostgreSQL doesn't even see that there's a
> candidate.

Allowing Pg to assign parameters or fields by using the
normally-only-explicit casts where no ambiguity exists would be *really*
helpful in other areas, too.

In particular, this applies with assignment of fields from `text' input,
too. PostgreSQL can be incredibly frustrating to work with from
Java/JDBC where everything goes through protocol-level parameterised
statements, because you can't use Java `String' types via
PreparedStatement.setString() to assign to, say, an `xml' or `json'
field, you have to use `setObject()'.

That's OK (ish) when working with PgJDBC directly, but it breaks code
that expects this to work like it does in other databases where
setString(...) can be used to assign to anything that's castable from
varchar.

Pg doesn't allow `unknown' to be passed as the type of a parameterised
statement, so the JDBC driver can't work around this by passing such
entries as fields of "unknown" type and letting the server work it out.
It'd instead have to ask the server "what are the permissible types for
the placeholder $1 in this query" ... which AFAIK isn't possible, and
would require extra round trips too.

I currently work around this by creating additional implicit casts where
I need them, eg text->xml, text->json. It'd be lovely not to have to do
that, though.

--
Craig Ringer

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2012-08-29 02:15:20 A note about add_path() and parameterized paths
Previous Message Andrew Dunstan 2012-08-29 01:32:40 Re: "default deny" for roles