pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: len.carlsen@ubc.ca
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #15171: JDBC TIMESTAMP WITH TIME ZONE PSQLException When Using Substitution Parameter
Date: Tue, 24 Apr 2018 19:22:01 -0400
Message-ID: <17552.1524612121@sss.pgh.pa.us> (raw)
In-Reply-To: <152459274229.19802.17031385353863581472@wrigleys.postgresql.org>
References: <152459274229.19802.17031385353863581472@wrigleys.postgresql.org>

=?utf-8?q?PG_Bug_reporting_form?= <noreply@postgresql.org> writes:
> 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.

Yes.  A parameter symbol is not a syntactic equivalent to a
string literal; it's more nearly like a variable.  You can't say
"typename variable" either.  You need to write it like a cast,
ie "variable::typename", or "CAST(variable AS typename)" if you
want to be pedantically standards-compliant.  So what you want is
"SELECT ?::TIMESTAMP WITH TIME ZONE".

(Allowing the non-orthogonal, non-extensible syntax "typename
string-literal" was not one of the SQL committee's better decisions
IMV.  We're stuck with supporting it, but I'd suggest avoiding it in
favor of cast-like notation, which works in a much wider variety of
cases.)

			regards, tom lane




view thread (3+ messages)  latest in thread

Message-ID: <17552.1524612121@sss.pgh.pa.us>
Permalink:  ../17552.1524612121@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/17552.1524612121@sss.pgh.pa.us

 · 

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

* 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