COPY SELECT with parameters

From: Ondřej Fafejta <ondrej(dot)fafejta(at)kyberie(dot)cz>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: COPY SELECT with parameters
Date: 2009-07-23 08:49:12
Message-ID: 4A682408.5000209@kyberie.cz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

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)

Browse pgsql-jdbc by date

  From Date Subject
Next Message nmset 2009-07-24 08:48:46 SSL - NonValidatingFactory
Previous Message Kris Jurka 2009-07-22 19:41:10 Re: Encoding from CopyManager.copyIn()