Skip site navigation (1) Skip section navigation (2)

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: (view raw, whole thread or download thread mbox)
Lists: pgsql-jdbc

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";

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);

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)

Ondrej Fafejta (fafi)

pgsql-jdbc by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group