pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feedRegression: Problems with Timestamp arguments
15+ messages / 5 participants
[nested] [flat]
* Regression: Problems with Timestamp arguments
@ 2013-09-10 09:17 Lachezar Dobrev <l.dobrev@gmail.com>
0 siblings, 1 reply; 15+ messages in thread
From: Lachezar Dobrev @ 2013-09-10 09:17 UTC (permalink / raw)
To: pgsql-jdbc
Hello colleagues,
There seems to be a problem with the latest driver and Timestamp
arguments uses in IS NULL comparisons:
QUERY: SELECT ? IS NULL
ARGUMENTS: statement.setTimestamp(1, new
Timestamp(System.currentTimeMillis()))
Result:
Exception in thread "main" org.postgresql.util.PSQLException: ERROR:
could not determine data type of parameter $1
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2157)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1886)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:555)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:417)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:302)
The problem arises on:
protocolVersion=3, or not specifying protocol version
argument type: Timestamp
The problem does not arise on other types (tested on BigDecimal and String)
The problem does not arise when using protocolVersion=2
The problem does not arise if the expression is not ? IS NULL
List of work-around methods:
- Degrade the protocol:
jdbc:postgresql://host:port/database?protocolVersion=2
* does not work with PgPool-2
- Explicitly cast the argument
SELECT ?::timestamp IS NULL
SELECT CAST(? AS timestamp) IS NULL
* requires rewriting of currently working code
I believe this to be a bug.
--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc
^ permalink raw reply [nested|flat] 15+ messages in thread
* Re: Regression: Problems with Timestamp arguments
@ 2013-09-10 09:57 Dave Cramer <pg@fastcrypt.com>
parent: Lachezar Dobrev <l.dobrev@gmail.com>
0 siblings, 2 replies; 15+ messages in thread
From: Dave Cramer @ 2013-09-10 09:57 UTC (permalink / raw)
To: Lachezar Dobrev <l.dobrev@gmail.com>; +Cc: pgsql-jdbc
Hi,
if you try this: prepare foo as select $1 is null;
in psql you will get
ERROR: could not determine data type of parameter $1
Why it works with integers I don't know yet, but thought I would pass that
along
Dave Cramer
dave.cramer(at)credativ(dot)ca
http://www.credativ.ca
On Tue, Sep 10, 2013 at 5:17 AM, Lachezar Dobrev <l.dobrev@gmail.com> wrote:
> Hello colleagues,
>
> There seems to be a problem with the latest driver and Timestamp
> arguments uses in IS NULL comparisons:
> QUERY: SELECT ? IS NULL
> ARGUMENTS: statement.setTimestamp(1, new
> Timestamp(System.currentTimeMillis()))
>
> Result:
> Exception in thread "main" org.postgresql.util.PSQLException: ERROR:
> could not determine data type of parameter $1
> at
> org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2157)
> at
> org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1886)
> at
> org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
> at
> org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:555)
> at
> org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:417)
> at
> org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:302)
>
> The problem arises on:
> protocolVersion=3, or not specifying protocol version
> argument type: Timestamp
>
> The problem does not arise on other types (tested on BigDecimal and
> String)
> The problem does not arise when using protocolVersion=2
> The problem does not arise if the expression is not ? IS NULL
>
> List of work-around methods:
> - Degrade the protocol:
> jdbc:postgresql://host:port/database?protocolVersion=2
> * does not work with PgPool-2
>
> - Explicitly cast the argument
> SELECT ?::timestamp IS NULL
> SELECT CAST(? AS timestamp) IS NULL
> * requires rewriting of currently working code
>
> I believe this to be a bug.
>
>
> --
> Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-jdbc
>
^ permalink raw reply [nested|flat] 15+ messages in thread
* Re: Regression: Problems with Timestamp arguments
@ 2013-09-10 10:10 Dave Cramer <pg@fastcrypt.com>
parent: Dave Cramer <pg@fastcrypt.com>
1 sibling, 1 reply; 15+ messages in thread
From: Dave Cramer @ 2013-09-10 10:10 UTC (permalink / raw)
To: Lachezar Dobrev <l.dobrev@gmail.com>; +Cc: pgsql-jdbc
OK, I recall the problem here. Timestamp is rather unique in that there are
two different types of timestamps with and without timezone.
As JDBC only has facility for one of them we have no way to say
setTimestampTZ so we allow the server to infer the type.
There is not much that can be done without breaking a bunch of other code,
however I am open to suggestions
Dave Cramer
dave.cramer(at)credativ(dot)ca
http://www.credativ.ca
On Tue, Sep 10, 2013 at 5:57 AM, Dave Cramer <pg@fastcrypt.com> wrote:
> Hi,
>
> if you try this: prepare foo as select $1 is null;
> in psql you will get
> ERROR: could not determine data type of parameter $1
>
> Why it works with integers I don't know yet, but thought I would pass that
> along
>
> Dave Cramer
>
> dave.cramer(at)credativ(dot)ca
> http://www.credativ.ca
>
>
> On Tue, Sep 10, 2013 at 5:17 AM, Lachezar Dobrev <l.dobrev@gmail.com>wrote:
>
>> Hello colleagues,
>>
>> There seems to be a problem with the latest driver and Timestamp
>> arguments uses in IS NULL comparisons:
>> QUERY: SELECT ? IS NULL
>> ARGUMENTS: statement.setTimestamp(1, new
>> Timestamp(System.currentTimeMillis()))
>>
>> Result:
>> Exception in thread "main" org.postgresql.util.PSQLException: ERROR:
>> could not determine data type of parameter $1
>> at
>> org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2157)
>> at
>> org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1886)
>> at
>> org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
>> at
>> org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:555)
>> at
>> org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:417)
>> at
>> org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:302)
>>
>> The problem arises on:
>> protocolVersion=3, or not specifying protocol version
>> argument type: Timestamp
>>
>> The problem does not arise on other types (tested on BigDecimal and
>> String)
>> The problem does not arise when using protocolVersion=2
>> The problem does not arise if the expression is not ? IS NULL
>>
>> List of work-around methods:
>> - Degrade the protocol:
>> jdbc:postgresql://host:port/database?protocolVersion=2
>> * does not work with PgPool-2
>>
>> - Explicitly cast the argument
>> SELECT ?::timestamp IS NULL
>> SELECT CAST(? AS timestamp) IS NULL
>> * requires rewriting of currently working code
>>
>> I believe this to be a bug.
>>
>>
>> --
>> Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
>> To make changes to your subscription:
>> http://www.postgresql.org/mailpref/pgsql-jdbc
>>
>
>
^ permalink raw reply [nested|flat] 15+ messages in thread
* Re: Regression: Problems with Timestamp arguments
@ 2013-09-10 10:48 Lachezar Dobrev <l.dobrev@gmail.com>
parent: Dave Cramer <pg@fastcrypt.com>
0 siblings, 2 replies; 15+ messages in thread
From: Lachezar Dobrev @ 2013-09-10 10:48 UTC (permalink / raw)
To: pgsql-jdbc
I (believe I) understand the issue.
May I suggest a parameter to the Connection URL to specify how
Timestamp is sent to the server.
I am not versed enough to make a patch to hold this proposal, but if
I must I will try to.
How is this problem «solved» when using protocol version 2?
Is there a way to degrade certain parts of the protocol?
2013/9/10 Dave Cramer <pg@fastcrypt.com>:
> OK, I recall the problem here. Timestamp is rather unique in that there are
> two different types of timestamps with and without timezone.
>
> As JDBC only has facility for one of them we have no way to say
> setTimestampTZ so we allow the server to infer the type.
>
> There is not much that can be done without breaking a bunch of other code,
> however I am open to suggestions
>
> Dave Cramer
>
> dave.cramer(at)credativ(dot)ca
> http://www.credativ.ca
>
>
> On Tue, Sep 10, 2013 at 5:57 AM, Dave Cramer <pg@fastcrypt.com> wrote:
>>
>> Hi,
>>
>> if you try this: prepare foo as select $1 is null;
>> in psql you will get
>> ERROR: could not determine data type of parameter $1
>>
>> Why it works with integers I don't know yet, but thought I would pass that
>> along
>>
>> Dave Cramer
>>
>> dave.cramer(at)credativ(dot)ca
>> http://www.credativ.ca
>>
>>
>> On Tue, Sep 10, 2013 at 5:17 AM, Lachezar Dobrev <l.dobrev@gmail.com>
>> wrote:
>>>
>>> Hello colleagues,
>>>
>>> There seems to be a problem with the latest driver and Timestamp
>>> arguments uses in IS NULL comparisons:
>>> QUERY: SELECT ? IS NULL
>>> ARGUMENTS: statement.setTimestamp(1, new
>>> Timestamp(System.currentTimeMillis()))
>>>
>>> Result:
>>> Exception in thread "main" org.postgresql.util.PSQLException: ERROR:
>>> could not determine data type of parameter $1
>>> at
>>> org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2157)
>>> at
>>> org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1886)
>>> at
>>> org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
>>> at
>>> org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:555)
>>> at
>>> org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:417)
>>> at
>>> org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:302)
>>>
>>> The problem arises on:
>>> protocolVersion=3, or not specifying protocol version
>>> argument type: Timestamp
>>>
>>> The problem does not arise on other types (tested on BigDecimal and
>>> String)
>>> The problem does not arise when using protocolVersion=2
>>> The problem does not arise if the expression is not ? IS NULL
>>>
>>> List of work-around methods:
>>> - Degrade the protocol:
>>> jdbc:postgresql://host:port/database?protocolVersion=2
>>> * does not work with PgPool-2
>>>
>>> - Explicitly cast the argument
>>> SELECT ?::timestamp IS NULL
>>> SELECT CAST(? AS timestamp) IS NULL
>>> * requires rewriting of currently working code
>>>
>>> I believe this to be a bug.
>>>
>>>
>>> --
>>> Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
>>> To make changes to your subscription:
>>> http://www.postgresql.org/mailpref/pgsql-jdbc
>>
>>
>
--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc
^ permalink raw reply [nested|flat] 15+ messages in thread
* Re: Regression: Problems with Timestamp arguments
@ 2013-09-10 11:07 Lachezar Dobrev <l.dobrev@gmail.com>
parent: Dave Cramer <pg@fastcrypt.com>
1 sibling, 0 replies; 15+ messages in thread
From: Lachezar Dobrev @ 2013-09-10 11:07 UTC (permalink / raw)
To: Dave Cramer <pg@fastcrypt.com>; +Cc: pgsql-jdbc
This works:
PREPARE is_date_reached AS SELECT NOW() < $1 OR $1 IS NULL;
However JDBC can not use the same parameter more than once…
SELECT NOW() < ? OR ? IS NULL;
Hmm. That's not good.
2013/9/10 Dave Cramer <pg@fastcrypt.com>:
> Hi,
>
> if you try this: prepare foo as select $1 is null;
> in psql you will get
> ERROR: could not determine data type of parameter $1
>
> Why it works with integers I don't know yet, but thought I would pass that
> along
>
> Dave Cramer
>
> dave.cramer(at)credativ(dot)ca
> http://www.credativ.ca
>
>
> On Tue, Sep 10, 2013 at 5:17 AM, Lachezar Dobrev <l.dobrev@gmail.com> wrote:
>>
>> Hello colleagues,
>>
>> There seems to be a problem with the latest driver and Timestamp
>> arguments uses in IS NULL comparisons:
>> QUERY: SELECT ? IS NULL
>> ARGUMENTS: statement.setTimestamp(1, new
>> Timestamp(System.currentTimeMillis()))
>>
>> Result:
>> Exception in thread "main" org.postgresql.util.PSQLException: ERROR:
>> could not determine data type of parameter $1
>> at
>> org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2157)
>> at
>> org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1886)
>> at
>> org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
>> at
>> org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:555)
>> at
>> org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:417)
>> at
>> org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:302)
>>
>> The problem arises on:
>> protocolVersion=3, or not specifying protocol version
>> argument type: Timestamp
>>
>> The problem does not arise on other types (tested on BigDecimal and
>> String)
>> The problem does not arise when using protocolVersion=2
>> The problem does not arise if the expression is not ? IS NULL
>>
>> List of work-around methods:
>> - Degrade the protocol:
>> jdbc:postgresql://host:port/database?protocolVersion=2
>> * does not work with PgPool-2
>>
>> - Explicitly cast the argument
>> SELECT ?::timestamp IS NULL
>> SELECT CAST(? AS timestamp) IS NULL
>> * requires rewriting of currently working code
>>
>> I believe this to be a bug.
>>
>>
>> --
>> Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
>> To make changes to your subscription:
>> http://www.postgresql.org/mailpref/pgsql-jdbc
>
>
--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc
^ permalink raw reply [nested|flat] 15+ messages in thread
* Re: Regression: Problems with Timestamp arguments
@ 2013-09-10 11:23 Dave Cramer <pg@fastcrypt.com>
parent: Lachezar Dobrev <l.dobrev@gmail.com>
1 sibling, 1 reply; 15+ messages in thread
From: Dave Cramer @ 2013-09-10 11:23 UTC (permalink / raw)
To: Lachezar Dobrev <l.dobrev@gmail.com>; +Cc: pgsql-jdbc
Protocol 2 just does textual replacement of the parameters and does not use
prepared statements on the server.
There is no way to degrade only certain parts. Why is it not possible to
cast this to timestamp ?
Dave Cramer
dave.cramer(at)credativ(dot)ca
http://www.credativ.ca
On Tue, Sep 10, 2013 at 6:48 AM, Lachezar Dobrev <l.dobrev@gmail.com> wrote:
> I (believe I) understand the issue.
> May I suggest a parameter to the Connection URL to specify how
> Timestamp is sent to the server.
>
> I am not versed enough to make a patch to hold this proposal, but if
> I must I will try to.
>
> How is this problem «solved» when using protocol version 2?
> Is there a way to degrade certain parts of the protocol?
>
>
> 2013/9/10 Dave Cramer <pg@fastcrypt.com>:
> > OK, I recall the problem here. Timestamp is rather unique in that there
> are
> > two different types of timestamps with and without timezone.
> >
> > As JDBC only has facility for one of them we have no way to say
> > setTimestampTZ so we allow the server to infer the type.
> >
> > There is not much that can be done without breaking a bunch of other
> code,
> > however I am open to suggestions
> >
> > Dave Cramer
> >
> > dave.cramer(at)credativ(dot)ca
> > http://www.credativ.ca
> >
> >
> > On Tue, Sep 10, 2013 at 5:57 AM, Dave Cramer <pg@fastcrypt.com> wrote:
> >>
> >> Hi,
> >>
> >> if you try this: prepare foo as select $1 is null;
> >> in psql you will get
> >> ERROR: could not determine data type of parameter $1
> >>
> >> Why it works with integers I don't know yet, but thought I would pass
> that
> >> along
> >>
> >> Dave Cramer
> >>
> >> dave.cramer(at)credativ(dot)ca
> >> http://www.credativ.ca
> >>
> >>
> >> On Tue, Sep 10, 2013 at 5:17 AM, Lachezar Dobrev <l.dobrev@gmail.com>
> >> wrote:
> >>>
> >>> Hello colleagues,
> >>>
> >>> There seems to be a problem with the latest driver and Timestamp
> >>> arguments uses in IS NULL comparisons:
> >>> QUERY: SELECT ? IS NULL
> >>> ARGUMENTS: statement.setTimestamp(1, new
> >>> Timestamp(System.currentTimeMillis()))
> >>>
> >>> Result:
> >>> Exception in thread "main" org.postgresql.util.PSQLException: ERROR:
> >>> could not determine data type of parameter $1
> >>> at
> >>>
> org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2157)
> >>> at
> >>>
> org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1886)
> >>> at
> >>>
> org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
> >>> at
> >>>
> org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:555)
> >>> at
> >>>
> org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:417)
> >>> at
> >>>
> org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:302)
> >>>
> >>> The problem arises on:
> >>> protocolVersion=3, or not specifying protocol version
> >>> argument type: Timestamp
> >>>
> >>> The problem does not arise on other types (tested on BigDecimal and
> >>> String)
> >>> The problem does not arise when using protocolVersion=2
> >>> The problem does not arise if the expression is not ? IS NULL
> >>>
> >>> List of work-around methods:
> >>> - Degrade the protocol:
> >>> jdbc:postgresql://host:port/database?protocolVersion=2
> >>> * does not work with PgPool-2
> >>>
> >>> - Explicitly cast the argument
> >>> SELECT ?::timestamp IS NULL
> >>> SELECT CAST(? AS timestamp) IS NULL
> >>> * requires rewriting of currently working code
> >>>
> >>> I believe this to be a bug.
> >>>
> >>>
> >>> --
> >>> Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
> >>> To make changes to your subscription:
> >>> http://www.postgresql.org/mailpref/pgsql-jdbc
> >>
> >>
> >
>
>
> --
> Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-jdbc
>
^ permalink raw reply [nested|flat] 15+ messages in thread
* Re: Regression: Problems with Timestamp arguments
@ 2013-09-10 11:56 Lachezar Dobrev <l.dobrev@gmail.com>
parent: Dave Cramer <pg@fastcrypt.com>
0 siblings, 0 replies; 15+ messages in thread
From: Lachezar Dobrev @ 2013-09-10 11:56 UTC (permalink / raw)
To: Dave Cramer <pg@fastcrypt.com>; +Cc: pgsql-jdbc
2013/9/10 Dave Cramer <pg@fastcrypt.com>:
> Protocol 2 just does textual replacement of the parameters and does not use
> prepared statements on the server.
I see…
That would also answer another question about why null arguments
fail with the current protocol, but don't with protocol 2 (Hibernate
uses Serializable -> bytea which can not be used in any way).
> There is no way to degrade only certain parts. Why is it not possible to
> cast this to timestamp ?
That works:
SELECT CAST(? AS TIMESTAMP) IS NULL;
However this is something that would mandate rewriting hundreds of
queries in a working (with protocol version 2) product.
> Dave Cramer
>
> dave.cramer(at)credativ(dot)ca
> http://www.credativ.ca
--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc
^ permalink raw reply [nested|flat] 15+ messages in thread
* Re: Regression: Problems with Timestamp arguments
@ 2013-09-10 18:00 Lachezar Dobrev <l.dobrev@gmail.com>
parent: Lachezar Dobrev <l.dobrev@gmail.com>
1 sibling, 2 replies; 15+ messages in thread
From: Lachezar Dobrev @ 2013-09-10 18:00 UTC (permalink / raw)
To: pgsql-jdbc
I've made a blunt stab at working around the issue.
The attached patch adds a new parameter to the JDBC URL: timestamp.
The parameter can be wither 'with_timezone' or 'without_timezone'. If
the parameter is missing, or has a different value then the current
behaviour (using Oid.UNSPECIFIED) is exhibited. With the parameters
specified correctly one of the Oid.TIMESTAMP or Oid.TIMESTAMPTZ is
used when sending Timestamp arguments to the server.
I am not sure whether this is the correct way to request new
features/enhancements, or what is the work-flow for accepting patches,
so feel free to scold me.
I believe the patch to be backwards compatible and very
light-weight, but it may deviate from the code formatting and code
practices of the project.
2013/9/10 Lachezar Dobrev <l.dobrev@gmail.com>:
> I (believe I) understand the issue.
> May I suggest a parameter to the Connection URL to specify how
> Timestamp is sent to the server.
>
> I am not versed enough to make a patch to hold this proposal, but if
> I must I will try to.
>
> How is this problem «solved» when using protocol version 2?
> Is there a way to degrade certain parts of the protocol?
--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc
Attachments:
timestamp.patch (application/octet-stream, 3.1K) download
Only in src/: TestQueryWithNullArgument.java
diff -ru old/org/postgresql/jdbc2/AbstractJdbc2Connection.java src/org/postgresql/jdbc2/AbstractJdbc2Connection.java
--- old/org/postgresql/jdbc2/AbstractJdbc2Connection.java 2013-09-10 19:59:31.661212020 +0300
+++ src/org/postgresql/jdbc2/AbstractJdbc2Connection.java 2013-09-10 19:56:39.161203807 +0300
@@ -228,9 +228,15 @@
bindStringAsVarchar = haveMinimumCompatibleVersion("8.0");
}
+ int timestamp_oid;
+ timestamp_oid = Oid.UNSPECIFIED; // Default
+ if ("with_timezone".equals(info.getProperty("timestamp")))
+ timestamp_oid = Oid.TIMESTAMPTZ;
+ if ("without_timezone".equals(info.getProperty("timestamp")))
+ timestamp_oid = Oid.TIMESTAMP;
// Initialize timestamp stuff
timestampUtils = new TimestampUtils(haveMinimumServerVersion("7.4"), haveMinimumServerVersion("8.2"),
- !protoConnection.getIntegerDateTimes());
+ !protoConnection.getIntegerDateTimes(), timestamp_oid);
// Initialize common queries.
commitQuery = getQueryExecutor().createSimpleQuery("COMMIT");
diff -ru old/org/postgresql/jdbc2/AbstractJdbc2Statement.java src/org/postgresql/jdbc2/AbstractJdbc2Statement.java
--- old/org/postgresql/jdbc2/AbstractJdbc2Statement.java 2013-09-10 19:59:44.405212627 +0300
+++ src/org/postgresql/jdbc2/AbstractJdbc2Statement.java 2013-09-10 20:03:43.781224024 +0300
@@ -3315,7 +3315,8 @@
// we're actually dealing with, UNSPECIFIED seems the lesser evil, even if it
// does give more scope for type-mismatch errors being silently hidden.
- bindString(i, connection.getTimestampUtils().toString(cal, t), Oid.UNSPECIFIED); // Let the server infer the right type.
+ TimestampUtils utils = connection.getTimestampUtils();
+ bindString(i, utils.toString(cal, t), utils.timestampOid); // Let the server infer the right type.
}
// ** JDBC 2 Extensions for CallableStatement**
diff -ru old/org/postgresql/jdbc2/TimestampUtils.java src/org/postgresql/jdbc2/TimestampUtils.java
--- old/org/postgresql/jdbc2/TimestampUtils.java 2013-09-10 19:59:11.905211079 +0300
+++ src/org/postgresql/jdbc2/TimestampUtils.java 2013-09-10 20:07:20.785234356 +0300
@@ -47,10 +47,27 @@
*/
private final boolean usesDouble;
+ /**
+ * OID to use for {@link Timestamp} type.<br>
+ * Must be one of:
+ * <ul>
+ * <li>{@link Oid#UNSPECIFIED}</li>
+ * <li>{@link Oid#TIMESTAMP}</li>
+ * <li>{@link Oid#TIMESTAMPTZ}</li>
+ * </ul>
+ * Typically should be set from the JDBC URL or parameters.
+ */
+ public final int timestampOid;
+
TimestampUtils(boolean min74, boolean min82, boolean usesDouble) {
+ this(min74, min82, usesDouble, Oid.UNSPECIFIED);
+ }
+
+ TimestampUtils(boolean min74, boolean min82, boolean usesDouble, int timestampOid) {
this.min74 = min74;
this.min82 = min82;
this.usesDouble = usesDouble;
+ this.timestampOid = timestampOid;
}
private Calendar getCalendar(int sign, int hr, int min, int sec) {
^ permalink raw reply [nested|flat] 15+ messages in thread
* Re: Regression: Problems with Timestamp arguments
@ 2013-09-10 18:02 Lachezar Dobrev <l.dobrev@gmail.com>
parent: Lachezar Dobrev <l.dobrev@gmail.com>
1 sibling, 0 replies; 15+ messages in thread
From: Lachezar Dobrev @ 2013-09-10 18:02 UTC (permalink / raw)
To: pgsql-jdbc
Please note, that a parasite line (for a missing file) had slipped
into the patch.
I apologise for that. I will remake the patch if needed.
2013/9/10 Lachezar Dobrev <l.dobrev@gmail.com>:
> I've made a blunt stab at working around the issue.
> The attached patch adds a new parameter to the JDBC URL: timestamp.
> The parameter can be wither 'with_timezone' or 'without_timezone'. If
> the parameter is missing, or has a different value then the current
> behaviour (using Oid.UNSPECIFIED) is exhibited. With the parameters
> specified correctly one of the Oid.TIMESTAMP or Oid.TIMESTAMPTZ is
> used when sending Timestamp arguments to the server.
>
> I am not sure whether this is the correct way to request new
> features/enhancements, or what is the work-flow for accepting patches,
> so feel free to scold me.
>
> I believe the patch to be backwards compatible and very
> light-weight, but it may deviate from the code formatting and code
> practices of the project.
>
>
> 2013/9/10 Lachezar Dobrev <l.dobrev@gmail.com>:
>> I (believe I) understand the issue.
>> May I suggest a parameter to the Connection URL to specify how
>> Timestamp is sent to the server.
>>
>> I am not versed enough to make a patch to hold this proposal, but if
>> I must I will try to.
>>
>> How is this problem «solved» when using protocol version 2?
>> Is there a way to degrade certain parts of the protocol?
--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc
^ permalink raw reply [nested|flat] 15+ messages in thread
* Re: Regression: Problems with Timestamp arguments
@ 2013-09-10 22:37 Kris Jurka <books@ejurka.com>
parent: Lachezar Dobrev <l.dobrev@gmail.com>
1 sibling, 2 replies; 15+ messages in thread
From: Kris Jurka @ 2013-09-10 22:37 UTC (permalink / raw)
To: Lachezar Dobrev <l.dobrev@gmail.com>; +Cc: pgsql-jdbc
On Tue, 10 Sep 2013, Lachezar Dobrev wrote:
> I've made a blunt stab at working around the issue.
> The attached patch adds a new parameter to the JDBC URL: timestamp.
> The parameter can be wither 'with_timezone' or 'without_timezone'. If
> the parameter is missing, or has a different value then the current
> behaviour (using Oid.UNSPECIFIED) is exhibited. With the parameters
> specified correctly one of the Oid.TIMESTAMP or Oid.TIMESTAMPTZ is
> used when sending Timestamp arguments to the server.
This won't really work in general though. If you have a database that has
both timestamp and timestamptz fields in it, there is no valid setting of
this configuration option. Setting it either way will result in silent
corruption of your data.
Kris Jurka
--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc
^ permalink raw reply [nested|flat] 15+ messages in thread
* Re: Regression: Problems with Timestamp arguments
@ 2013-09-11 06:03 Vitalii Tymchyshyn <vit@tym.im>
parent: Kris Jurka <books@ejurka.com>
1 sibling, 1 reply; 15+ messages in thread
From: Vitalii Tymchyshyn @ 2013-09-11 06:03 UTC (permalink / raw)
To: Kris Jurka <books@ejurka.com>; +Cc: Lachezar Dobrev <l.dobrev@gmail.com>; pgsql-jdbc
Why so? I thought if driver will pass timestamp with tz some queries won't
work because of lack of implicit conversion, but I don't understand how can
it corrupt anything.
11 вер. 2013 01:37, "Kris Jurka" <books@ejurka.com> напис.
>
>
> On Tue, 10 Sep 2013, Lachezar Dobrev wrote:
>
> > I've made a blunt stab at working around the issue.
> > The attached patch adds a new parameter to the JDBC URL: timestamp.
> > The parameter can be wither 'with_timezone' or 'without_timezone'. If
> > the parameter is missing, or has a different value then the current
> > behaviour (using Oid.UNSPECIFIED) is exhibited. With the parameters
> > specified correctly one of the Oid.TIMESTAMP or Oid.TIMESTAMPTZ is
> > used when sending Timestamp arguments to the server.
>
> This won't really work in general though. If you have a database that has
> both timestamp and timestamptz fields in it, there is no valid setting of
> this configuration option. Setting it either way will result in silent
> corruption of your data.
>
> Kris Jurka
>
>
> --
> Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-jdbc
>
^ permalink raw reply [nested|flat] 15+ messages in thread
* Re: Regression: Problems with Timestamp arguments
@ 2013-09-11 06:37 Kris Jurka <books@ejurka.com>
parent: Vitalii Tymchyshyn <vit@tym.im>
0 siblings, 0 replies; 15+ messages in thread
From: Kris Jurka @ 2013-09-11 06:37 UTC (permalink / raw)
To: Vitalii Tymchyshyn <vit@tym.im>; +Cc: Lachezar Dobrev <l.dobrev@gmail.com>; pgsql-jdbc
On Wed, 11 Sep 2013, Vitalii Tymchyshyn wrote:
> Why so? I thought if driver will pass timestamp with tz some queries won't
> work because of lack of implicit conversion, but I don't understand how can
> it corrupt anything.
>
It's rather complicated, but currently without knowing the datatype on the
server side, the driver must pick a datatype (timestamp with or without
timestamp or unknown) and a string representation of that data (include or
not the timezone offset). Now you can get away with this problem if the
client and server have the same timezone settings, but not if they don't.
Consider the attached test code. It prepares a statement with all three
datatype options and then executes each statement using both string
representations.
When the client and server timezones are the same, it doesn't matter what
method we use, all the results are the same. If they are different, then
only id 9 (unknown datatype, string with timezone offset) provides the
correct result for both table columns. It might be possible to work
around this by explicitly setting the server timezone or querying the
server for its timezone and making adjustments on the client side to the
data before sending it to the server.
Kris Jurka
--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc
Attachments:
tsbug.sql (text/plain, 1.6K) download
BEGIN;
CREATE TABLE tstest(
id int,
tswithout timestamp without time zone,
tswith timestamptz
);
SET timezone = 'America/New_York';
PREPARE ewithout (int, timestamp without time zone, timestamp without time zone)
AS INSERT INTO tstest (id, tswithout, tswith) VALUES ($1, $2, $3);
PREPARE ewith (int, timestamp with time zone, timestamp with time zone)
AS INSERT INTO tstest (id, tswithout, tswith) VALUES ($1, $2, $3);
PREPARE eunk (int, unknown, unknown)
AS INSERT INTO tstest (id, tswithout, tswith) VALUES ($1, $2, $3);
EXECUTE ewithout (1, '2013-09-09 12:34:56 -0400', '2013-09-09 12:34:56 -0400');
EXECUTE ewith (2, '2013-09-09 12:34:56 -0400', '2013-09-09 12:34:56 -0400');
EXECUTE eunk (3, '2013-09-09 12:34:56 -0400', '2013-09-09 12:34:56 -0400');
EXECUTE ewithout (4, '2013-09-09 12:34:56', '2013-09-09 12:34:56');
EXECUTE ewith (5, '2013-09-09 12:34:56', '2013-09-09 12:34:56');
EXECUTE eunk (6, '2013-09-09 12:34:56', '2013-09-09 12:34:56');
SELECT * FROM tstest;
DELETE FROM tstest;
SET timezone = 'America/Los_Angeles';
EXECUTE ewithout (7, '2013-09-09 12:34:56 -0400', '2013-09-09 12:34:56 -0400');
EXECUTE ewith (8, '2013-09-09 12:34:56 -0400', '2013-09-09 12:34:56 -0400');
EXECUTE eunk (9, '2013-09-09 12:34:56 -0400', '2013-09-09 12:34:56 -0400');
EXECUTE ewithout (10, '2013-09-09 12:34:56', '2013-09-09 12:34:56');
EXECUTE ewith (11, '2013-09-09 12:34:56', '2013-09-09 12:34:56');
EXECUTE eunk (12, '2013-09-09 12:34:56', '2013-09-09 12:34:56');
SET timezone = 'America/New_York';
SELECT * FROM tstest;
ROLLBACK;
^ permalink raw reply [nested|flat] 15+ messages in thread
* Re: Regression: Problems with Timestamp arguments
@ 2013-09-11 07:06 Lachezar Dobrev <l.dobrev@gmail.com>
parent: Kris Jurka <books@ejurka.com>
1 sibling, 1 reply; 15+ messages in thread
From: Lachezar Dobrev @ 2013-09-11 07:06 UTC (permalink / raw)
To: Kris Jurka <books@ejurka.com>; +Cc: pgsql-jdbc
You're technically correct.
Maybe this can be applied to NULL arguments only? Would that be
'more' acceptable?
Lately I've been proven wrong with many of my (reasonable)
expectations, but I *hope* NULL timestamps with or without time zones
are the same!
2013/9/11 Kris Jurka <books@ejurka.com>:
>
>
> On Tue, 10 Sep 2013, Lachezar Dobrev wrote:
>
>> I've made a blunt stab at working around the issue.
>> The attached patch adds a new parameter to the JDBC URL: timestamp.
>> The parameter can be wither 'with_timezone' or 'without_timezone'. If
>> the parameter is missing, or has a different value then the current
>> behaviour (using Oid.UNSPECIFIED) is exhibited. With the parameters
>> specified correctly one of the Oid.TIMESTAMP or Oid.TIMESTAMPTZ is
>> used when sending Timestamp arguments to the server.
>
> This won't really work in general though. If you have a database that has
> both timestamp and timestamptz fields in it, there is no valid setting of
> this configuration option. Setting it either way will result in silent
> corruption of your data.
>
> Kris Jurka
--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc
^ permalink raw reply [nested|flat] 15+ messages in thread
* Re: Regression: Problems with Timestamp arguments
@ 2013-09-11 07:12 Lachezar Dobrev <l.dobrev@gmail.com>
parent: Lachezar Dobrev <l.dobrev@gmail.com>
0 siblings, 0 replies; 15+ messages in thread
From: Lachezar Dobrev @ 2013-09-11 07:12 UTC (permalink / raw)
To: Kris Jurka <books@ejurka.com>; +Cc: pgsql-jdbc
Please disregard.
The problem is not with NULL arguments, but with any Timestamps.
2013/9/11 Lachezar Dobrev <l.dobrev@gmail.com>:
> You're technically correct.
>
> Maybe this can be applied to NULL arguments only? Would that be
> 'more' acceptable?
> Lately I've been proven wrong with many of my (reasonable)
> expectations, but I *hope* NULL timestamps with or without time zones
> are the same!
>
> 2013/9/11 Kris Jurka <books@ejurka.com>:
>>
>>
>> On Tue, 10 Sep 2013, Lachezar Dobrev wrote:
>>
>>> I've made a blunt stab at working around the issue.
>>> The attached patch adds a new parameter to the JDBC URL: timestamp.
>>> The parameter can be wither 'with_timezone' or 'without_timezone'. If
>>> the parameter is missing, or has a different value then the current
>>> behaviour (using Oid.UNSPECIFIED) is exhibited. With the parameters
>>> specified correctly one of the Oid.TIMESTAMP or Oid.TIMESTAMPTZ is
>>> used when sending Timestamp arguments to the server.
>>
>> This won't really work in general though. If you have a database that has
>> both timestamp and timestamptz fields in it, there is no valid setting of
>> this configuration option. Setting it either way will result in silent
>> corruption of your data.
>>
>> Kris Jurka
--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc
^ permalink raw reply [nested|flat] 15+ messages in thread
* Re: Regression: Problems with Timestamp arguments
@ 2013-09-11 09:16 Thor Michael Støre <thormichael@gmail.com>
0 siblings, 0 replies; 15+ messages in thread
From: Thor Michael Støre @ 2013-09-11 09:16 UTC (permalink / raw)
To: pgsql-jdbc; +Cc: l.dobrev@gmail.com
Hi,
On 11. sep. 2013, at 08:37, pgsql-jdbc-owner@postgresql.org wrote:
> From: Lachezar Dobrev <l.dobrev@gmail.com>
> Subject: Re: Regression: Problems with Timestamp arguments
> Date: 10. september 2013 13:07:28 CEST
> To: Dave Cramer <pg@fastcrypt.com>
> Cc: List <pgsql-jdbc@postgresql.org>
>
>
> This works:
> PREPARE is_date_reached AS SELECT NOW() < $1 OR $1 IS NULL;
>
> However JDBC can not use the same parameter more than once…
> SELECT NOW() < ? OR ? IS NULL;
>
> Hmm. That's not good.
How about:
SELECT NOW() < ? OR $1 IS NULL;
I've at least always managed to use the same parameters over again like that in JDBC under normal circumstances, thought that's been with types the driver knew about.
Thanks, Thor Michael
^ permalink raw reply [nested|flat] 15+ messages in thread
end of thread, other threads:[~2013-09-11 09:16 UTC | newest]
Thread overview: 15+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2013-09-10 09:17 Regression: Problems with Timestamp arguments Lachezar Dobrev <l.dobrev@gmail.com>
2013-09-10 09:57 ` Dave Cramer <pg@fastcrypt.com>
2013-09-10 10:10 ` Dave Cramer <pg@fastcrypt.com>
2013-09-10 10:48 ` Lachezar Dobrev <l.dobrev@gmail.com>
2013-09-10 11:23 ` Dave Cramer <pg@fastcrypt.com>
2013-09-10 11:56 ` Lachezar Dobrev <l.dobrev@gmail.com>
2013-09-10 18:00 ` Lachezar Dobrev <l.dobrev@gmail.com>
2013-09-10 18:02 ` Lachezar Dobrev <l.dobrev@gmail.com>
2013-09-10 22:37 ` Kris Jurka <books@ejurka.com>
2013-09-11 06:03 ` Vitalii Tymchyshyn <vit@tym.im>
2013-09-11 06:37 ` Kris Jurka <books@ejurka.com>
2013-09-11 07:06 ` Lachezar Dobrev <l.dobrev@gmail.com>
2013-09-11 07:12 ` Lachezar Dobrev <l.dobrev@gmail.com>
2013-09-10 11:07 ` Lachezar Dobrev <l.dobrev@gmail.com>
2013-09-11 09:16 Re: Regression: Problems with Timestamp arguments Thor Michael Støre <thormichael@gmail.com>
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