pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ondřej Fafejta <ondrej.fafejta@kyberie.cz>
To: pgsql-jdbc@postgresql.org
Subject: COPY SELECT with parameters
Date: Thu, 23 Jul 2009 10:49:12 +0200
Message-ID: <4A682408.5000209@kyberie.cz> (raw)

Hi,

I think there is bug in jdbc driver.
I need to add some parameters to query by PreparedStatement -
setString(1,'some text');
If the query begins with COPY (SELECT, it does not work.

1. it works
String query = "COPY (SELECT id, name FROM test_text WHERE id<10) TO
'/tmp/test.csv' csv";
con.createStatement().execute(query);

2. it does not work
String query = "COPY (SELECT id, name FROM test_text WHERE id<?) TO
'/tmp/test.csv' csv";
PreparedStatement st = con.prepareStatement(query);
st.setInt(1, 10);
st.execute();

It throws exception:
org.postgresql.util.PSQLException: ERROR: no value found for parameter 1

I tested it on jdbc driver version:
- PostgreSQL 8.3 JDBC3 with SSL (build 603)

Thanks
Ondrej Fafejta (fafi)



Message-ID: <4A682408.5000209@kyberie.cz>
Permalink:  ../4A682408.5000209@kyberie.cz/
Also on:    postgresql.org/message-id/4A682408.5000209@kyberie.cz

 · 

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: ondrej.fafejta@kyberie.cz
  Subject: Re: COPY SELECT with parameters
  In-Reply-To: <4A682408.5000209@kyberie.cz>
  References: <4A682408.5000209@kyberie.cz>

* 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