pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Kris Jurka <books@ejurka.com>
To: Russell Francis <rfrancis@ev.net>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: queries against CIDR fail against 8.0.3?
Date: Thu, 29 Sep 2005 12:12:50 -0500 (EST)
Message-ID: <Pine.BSO.4.61.0509291206240.25137@leary.csoft.net> (raw)
In-Reply-To: <433BE38F.3080605@ev.net>
References: <433BE38F.3080605@ev.net>



On Thu, 29 Sep 2005, Russell Francis wrote:

> I have a web application which is running against PG 7.3.9 and seems to
> work without a problem.  Recently, I have been trying to run it against
> 8.0.3.  In both cases, I am using the jdbc3-8.0-312 driver.
>
> PreparedStatement s = dbConn.prepareStatement(
> "SELECT * FROM institution WHERE ( institution.network >>=  ? ) LIMIT 1" );
> s.setObject( 1, (String)request.getRemoteAddr() );
> if( s.execute() )
> {
> 	...
> }
>
> DEBUG http-8180-Processor25 net.fitne.vlrc.actions.IndexAction - ERROR:
> operator does not exist: cidr >>= character varying
> net.ev.dao.DAOException: ERROR: operator does not exist: cidr >>=
> character varying
>
> Does anyone have any ideas on how to address this issue?  Or at least an
> explanation as to why it works in 7.3.9 but not 8.0.3?
>

The 8.0 driver has added full V3 protocol support which is not available 
in 7.3 servers, so it falls back to using the V2 protocol when connecting 
to the 7.3 server.  Now, the 8.0 server fails because the V3 protocol uses 
real prepared statements.  When you call setString() you are telling the 
driver that you will be passing a string parameter, so it prepares a 
server side statement taking a string data type.  This is the difference 
between:

V2: WHERE network >>= '10.1.3.1'
V3: WHERE network >>= '10.1.3.1'::varchar

The first treats the parameter as an unknown literal which allows more 
liberal casting while the second has the parameter type somewhat nailed 
down.

The easiest solution is to write your query as "WHERE network >>= ?::cidr" 
to so you get the correct type.

Kris Jurka




view thread (10+ messages)  latest in thread

Message-ID: <Pine.BSO.4.61.0509291206240.25137@leary.csoft.net>
Permalink:  ../Pine.BSO.4.61.0509291206240.25137@leary.csoft.net/
Also on:    postgresql.org/message-id/Pine.BSO.4.61.0509291206240.25137@leary.csoft.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: books@ejurka.com, rfrancis@ev.net
  Subject: Re: queries against CIDR fail against 8.0.3?
  In-Reply-To: <Pine.BSO.4.61.0509291206240.25137@leary.csoft.net>
  References: <433BE38F.3080605@ev.net> <Pine.BSO.4.61.0509291206240.25137@leary.csoft.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox