could not determine data type of parameter $1, while executing COPY..TO statement
<p>I want to write the content of a table from the database into CSV file using JDBC prepared statement. The PSQL query that I am using is:</p>

<pre><code>COPY(select * from file where uploaded_at &gt; ?) TO '/tmp/file_info.csv' With DELIMITER ',' CSV HEADER ";
</code></pre>

<p>My code is as follows:</p>

<pre><code>private void copyData(Connection conn, Date date){
String sql = "COPY (select * from file where uploaded_at&lt; ?) TO '/tmp/file_info.csv' With DELIMITER ',' CSV HEADER ";
PreparedStatement stmt = conn.prepareStatement(sql);
stmt.setTimestamp(1, new Timestamp(date.getTime()));
stmt.execute();
}
</code></pre>

<p>I get the following stack when I run this query:</p>

<pre><code>org.postgresql.util.PSQLException: ERROR: could not determine data type of parameter $1
    at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2103)
    at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1836)
    at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:512)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:388)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:381)
    at tests.com.paramatrix.pace.archival.file.TestFileArchival.main(TestFileArchival.java:63)
</code></pre>

<p>This exception is not generated while running a simple select query like:</p>

<pre><code>select * from file where uploaded_at &gt; ?
</code></pre>

<p>What could be the reason for it not working with COPY..TO statement? </p>