pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: len.carlsen@ubc.ca
Subject: BUG #15171: JDBC TIMESTAMP WITH TIME ZONE PSQLException When Using Substitution Parameter
Date: Tue, 24 Apr 2018 17:59:02 +0000
Message-ID: <152459274229.19802.17031385353863581472@wrigleys.postgresql.org> (raw)

The following bug has been logged on the website:

Bug reference:      15171
Logged by:          Len Carlsen
Email address:      len.carlsen@ubc.ca
PostgreSQL version: 9.6.3
Operating system:   x86_64-pc-linux-gnu
Description:        

Hello,

I have looked through postgresql.org but can't to seem to find any
references to timestamp bugs so my apologies if this bug is already known.

Executing this query works fine: 'SELECT TIMESTAMP WITH TIME ZONE
'2018-04-17 12:00:00.0-07'"
But executing query "SELECT TIMESTAMP WITH TIME ZONE ?" with a substitution
parameter results in a PSQLException syntax error.

Postgresql 9.6.3 running on Amazon
Postgresql Driver 42.2.2

Exception:
org.postgresql.util.PSQLException: ERROR: syntax error at or near "$1"
  Position: 33
	at
org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2433)
	at
org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2178)
	at
org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:306)
	at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:441)
	at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:365)
	at
org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:155)
	at
org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.java:118)
	at PostgresqlTimestampTest.testTimestamp(PostgresqlTimestampTest.java:51)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
	at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

Sample Test:
Class.forName("org.postgresql.Driver");
String url = "jdbc:postgresql://" + host + ":" + port + "/" + instance;
Connection connection = DriverManager.getConnection(url, user, password);

PreparedStatement stmt2 = connection.prepareStatement("SELECT TIMESTAMP WITH
TIME ZONE ?");
java.sql.Timestamp timestamp = new java.sql.Timestamp((new
Date()).getTime());
stmt2.setTimestamp(1, timestamp);
ResultSet resultSet2 = stmt2.executeQuery();
resultSet2.next();
resultSet2.close();
stmt2.close();
connection.close();

Thanks,

Len



view thread (3+ messages)  latest in thread

Message-ID: <152459274229.19802.17031385353863581472@wrigleys.postgresql.org>
Permalink:  ../152459274229.19802.17031385353863581472@wrigleys.postgresql.org/
Also on:    postgresql.org/message-id/152459274229.19802.17031385353863581472@wrigleys.postgresql.org

 · 

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-bugs@postgresql.org
  Cc: noreply@postgresql.org, len.carlsen@ubc.ca
  Subject: Re: BUG #15171: JDBC TIMESTAMP WITH TIME ZONE PSQLException When Using Substitution Parameter
  In-Reply-To: <152459274229.19802.17031385353863581472@wrigleys.postgresql.org>
  References: <152459274229.19802.17031385353863581472@wrigleys.postgresql.org>

* 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