From: Kris Jurka <books@ejurka.com>
To: Vitalii Tymchyshyn <vit@tym.im>
Cc: Lachezar Dobrev <l.dobrev@gmail.com>
Cc: PG-JDBC Mailing List <pgsql-jdbc@postgresql.org>
Subject: Re: Regression: Problems with Timestamp arguments
Date: Wed, 11 Sep 2013 02:37:03 -0400 (EDT)
Message-ID: <alpine.BSO.2.03.1309110220450.18392@ejurka.com> (raw)
In-Reply-To: <CABWW-d3zq-Y3nkd3ra27mcaaeYPoF6OqjtUdBZf26qcTBGbBPg@mail.gmail.com>
References: <CA+xsaB0EMDaNek0Oky9c17_8UX3-epWVP11+vTNgrAPoY2s9FA@mail.gmail.com>
<CADK3HHLE=3ZMT5Qt+GTLUsAgq1LiFNdcqMqvw+ZqSb-rBTjF6w@mail.gmail.com>
<CADK3HHJnRLVUaRA0PgsJ1TfF5Aq2oKot77eqy1uhF2rxUXPDJQ@mail.gmail.com>
<CA+xsaB2MX7c-NeW7C_e_QcvAPCc8y03BZj4ML1GOOyeb4WwWDA@mail.gmail.com>
<CA+xsaB3UxRJwUq0Kro1CEzuURUj9KkNV5bJfJO+qCDtn6vqReA@mail.gmail.com>
<alpine.BSO.2.03.1309101834110.15199@ejurka.com>
<CABWW-d3zq-Y3nkd3ra27mcaaeYPoF6OqjtUdBZf26qcTBGbBPg@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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-jdbcAttachments: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;
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-jdbc@postgresql.org
Cc: books@ejurka.com, vit@tym.im, l.dobrev@gmail.com
Subject: Re: Regression: Problems with Timestamp arguments
In-Reply-To: <alpine.BSO.2.03.1309110220450.18392@ejurka.com>
References: <CA+xsaB0EMDaNek0Oky9c17_8UX3-epWVP11+vTNgrAPoY2s9FA@mail.gmail.com> <CADK3HHLE=3ZMT5Qt+GTLUsAgq1LiFNdcqMqvw+ZqSb-rBTjF6w@mail.gmail.com> <CADK3HHJnRLVUaRA0PgsJ1TfF5Aq2oKot77eqy1uhF2rxUXPDJQ@mail.gmail.com> <CA+xsaB2MX7c-NeW7C_e_QcvAPCc8y03BZj4ML1GOOyeb4WwWDA@mail.gmail.com> <CA+xsaB3UxRJwUq0Kro1CEzuURUj9KkNV5bJfJO+qCDtn6vqReA@mail.gmail.com> <alpine.BSO.2.03.1309101834110.15199@ejurka.com> <CABWW-d3zq-Y3nkd3ra27mcaaeYPoF6OqjtUdBZf26qcTBGbBPg@mail.gmail.com> <alpine.BSO.2.03.1309110220450.18392@ejurka.com>
* 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