Re: JBoss w/int8 primary keys in postgres ...

From: Oliver Jowett <oliver(at)opencloud(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: James Robinson <jlrobins(at)socialserve(dot)com>, Paul Thomas <paul(at)tmsl(dot)demon(dot)co(dot)uk>, "pgsql-jdbc (at) postgresql (dot) org" <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: JBoss w/int8 primary keys in postgres ...
Date: 2003-09-11 06:24:50
Message-ID: 20030911062448.GJ6485@opencloud.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

On Thu, Sep 11, 2003 at 01:40:21AM -0400, Tom Lane wrote:
> Oliver Jowett <oliver(at)opencloud(dot)com> writes:
> > which should use the index. However with server-side prepared queries
> > enabled the query is transformed to something like this:
>
> > PREPARE jdbc_statement_N(int8) AS SELECT * FROM foo WHERE bar = $1;
> > EXECUTE jdbc_statement_N(12345)
>
> > Which I suspect won't use the index as $1 is typed to int8. (anyone know for
> > sure? I can't find an easy way to get at the query plan produced by
> > PREPARE).
>
> In 7.4 you can do EXPLAIN EXECUTE. But no, this wouldn't use the index
> :-(. What exactly is causing the driver to decide to type the parameter
> as int8?

JDBC doesn't provide a separate parameter-typing step for parameterized
queries, so the driver has to infer the type from the method used to set the
actual value of a parameter. In this case, setLong() takes a Java long which
is a signed 64-bit integer, so the driver picks int8.

There's a more general interface (setObject()) that allows both a value and
a target SQL type to be specified, but that's not commonly used for
primitive types thanks to Java's primitive-vs-Object distinction.

See http://java.sun.com/j2se/1.4.2/docs/api/java/sql/PreparedStatement.html

-O

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message jonathan.lister 2003-09-11 07:55:10 Re: Stored Procedure returns a ResultSet
Previous Message Tom Lane 2003-09-11 05:40:21 Re: JBoss w/int8 primary keys in postgres ...