pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feedBug in storing Timestamp
6+ messages / 4 participants
[nested] [flat]
* Bug in storing Timestamp
@ 2005-04-11 12:39 Boris Kirzner <borisk@mainsoft.com>
2005-04-11 14:57 ` Re: Bug in storing Timestamp mikael-aronsson <mikael-aronsson@telia.com>
2005-04-14 09:17 ` Re: Bug in storing Timestamp Kris Jurka <books@ejurka.com>
0 siblings, 2 replies; 6+ messages in thread
From: Boris Kirzner @ 2005-04-11 12:39 UTC (permalink / raw)
To: pgsql-jdbc
Short description :
Storing java.sql.Timestamp with specified milliseconds value results to
wrong value stored in db.
System details :
OS : WindowsXP
PostgreSQL version : 8.0.1
Driver version : 8.0 build 310
Detailed description :
In order to reproduce the bug run the following code.
Create the table in the db.
The code creates a timestamp of "0001-01-01 02:02:02.0" and stores it
into the db.
The actual value stored is "02:22:42".
CREATE TABLE TYPES_EXTENDED (
id char(10),
t_time time
)
WITHOUT OIDS;
long milliseconds = Timestamp.valueOf("0001-01-01 02:02:02.0").getTime();
Timestamp javaTimestamp = new Timestamp(milliseconds);
System.out.println("Timestamp stored : " + javaTimestamp);
PreparedStatement stmt = connection.prepareStatement("insert into
types_extended(ID,t_time) values ('aaa',?)");
stmt.setTimestamp(1, javaTimestamp);
stmt.execute();
Thank you in advance,
--
Boris Kirzner
Mainsoft Corporation
http://www.mainsoft.com
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Bug in storing Timestamp
2005-04-11 12:39 Bug in storing Timestamp Boris Kirzner <borisk@mainsoft.com>
@ 2005-04-11 14:57 ` mikael-aronsson <mikael-aronsson@telia.com>
2005-04-11 15:07 ` Re: Bug in storing Timestamp Tom Lane <tgl@sss.pgh.pa.us>
1 sibling, 1 reply; 6+ messages in thread
From: mikael-aronsson @ 2005-04-11 14:57 UTC (permalink / raw)
To: Boris Kirzner <borisk@mainsoft.com>; pgsql-jdbc
Hi !
I have never had any problems with timestamps, if I remember correct the
resolution gets worse when you get far away from 1900 or so, is it possible
that using year 0001 gives that bad resolution maybe ?
Mikael
----- Original Message -----
From: "Boris Kirzner" <borisk@mainsoft.com>
To: <pgsql-jdbc@postgresql.org>
Sent: Monday, April 11, 2005 2:39 PM
Subject: [JDBC] Bug in storing Timestamp
> Short description :
> Storing java.sql.Timestamp with specified milliseconds value results to
> wrong value stored in db.
>
> System details :
> OS : WindowsXP
> PostgreSQL version : 8.0.1
> Driver version : 8.0 build 310
>
> Detailed description :
> In order to reproduce the bug run the following code.
> Create the table in the db.
> The code creates a timestamp of "0001-01-01 02:02:02.0" and stores it into
> the db.
> The actual value stored is "02:22:42".
>
>
> CREATE TABLE TYPES_EXTENDED (
> id char(10),
> t_time time
> )
> WITHOUT OIDS;
>
> long milliseconds = Timestamp.valueOf("0001-01-01 02:02:02.0").getTime();
> Timestamp javaTimestamp = new Timestamp(milliseconds);
> System.out.println("Timestamp stored : " + javaTimestamp);
> PreparedStatement stmt = connection.prepareStatement("insert into
> types_extended(ID,t_time) values ('aaa',?)");
> stmt.setTimestamp(1, javaTimestamp);
> stmt.execute();
>
>
> Thank you in advance,
>
> --
> Boris Kirzner
> Mainsoft Corporation
> http://www.mainsoft.com
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Bug in storing Timestamp
2005-04-11 12:39 Bug in storing Timestamp Boris Kirzner <borisk@mainsoft.com>
2005-04-11 14:57 ` Re: Bug in storing Timestamp mikael-aronsson <mikael-aronsson@telia.com>
@ 2005-04-11 15:07 ` Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 6+ messages in thread
From: Tom Lane @ 2005-04-11 15:07 UTC (permalink / raw)
To: mikael-aronsson <mikael-aronsson@telia.com>; +Cc: Boris Kirzner <borisk@mainsoft.com>; pgsql-jdbc
"mikael-aronsson" <mikael-aronsson@telia.com> writes:
> I have never had any problems with timestamps, if I remember correct the
> resolution gets worse when you get far away from 1900 or so, is it possible
> that using year 0001 gives that bad resolution maybe ?
Good thought, but no; the error at 0001 is still down around the sixth
decimal place:
regression=# select '0001-01-01 02:02:02.123456'::timestamp;
timestamp
----------------------------
0001-01-01 02:02:02.123459
(1 row)
I was wondering about the fact that he was storing into a time column
rather than a timestamp. That works if the conversion is done on the
server, modulo the sixth decimal place again:
regression=# select '0001-01-01 02:02:02.123456'::timestamp::time;
time
-----------------
02:02:02.123459
(1 row)
but maybe it's confusing the JDBC driver into doing the wrong thing
entirely.
regards, tom lane
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Bug in storing Timestamp
2005-04-11 12:39 Bug in storing Timestamp Boris Kirzner <borisk@mainsoft.com>
@ 2005-04-14 09:17 ` Kris Jurka <books@ejurka.com>
2005-04-21 12:39 ` Re: Bug in storing Timestamp Boris Kirzner <borisk@mainsoft.com>
1 sibling, 1 reply; 6+ messages in thread
From: Kris Jurka @ 2005-04-14 09:17 UTC (permalink / raw)
To: Boris Kirzner <borisk@mainsoft.com>; +Cc: pgsql-jdbc
On Mon, 11 Apr 2005, Boris Kirzner wrote:
> Short description :
> Storing java.sql.Timestamp with specified milliseconds value results to
> wrong value stored in db.
>
> PostgreSQL version : 8.0.1
> Driver version : 8.0 build 310
>
> Detailed description :
> In order to reproduce the bug run the following code.
> Create the table in the db.
> The code creates a timestamp of "0001-01-01 02:02:02.0" and stores it
> into the db.
> The actual value stored is "02:22:42".
I am not able to reproduce this problem. The attached test case shows a
problem with storing java.sql.Time into a timetz type because the correct
offset is not saved, but that's not what you've described. Perhaps it is
something specific to your timezone?
Kris Jurka
Attachments:
TimeTest.java (text/plain, 1.5K) download
import java.sql.*;
public class TimeTest {
public static void main(String args[]) throws Exception {
Class.forName("org.postgresql.Driver");
Connection conn = DriverManager.getConnection("jdbc:postgresql://192.168.3.150:5432/jurka","jurka","");
Statement stmt = conn.createStatement();
stmt.execute("CREATE TEMP TABLE tts (a time, b timetz)");
long ms = Timestamp.valueOf("0001-01-01 02:02:02.0").getTime();
Timestamp timestamp = new Timestamp(ms);
Time time = new Time(ms);
System.out.println("Orig Values:");
System.out.println(" " + timestamp + " - " + timestamp.getTimezoneOffset() / 60);
System.out.println(" " + time + " - " + time.getTimezoneOffset() / 60);
PreparedStatement pstmt = conn.prepareStatement("INSERT INTO tts VALUES (?,?)");
pstmt.setTimestamp(1, timestamp);
pstmt.setTimestamp(2, timestamp);
pstmt.executeUpdate();
pstmt.setTime(1, time);
pstmt.setTime(2, time);
pstmt.executeUpdate();
pstmt.close();
ResultSet rs = stmt.executeQuery("SELECT a,b FROM tts");
while(rs.next()) {
System.out.println("-------------");
for (int i=1; i<=2; i++) {
System.out.println(rs.getString(i));
System.out.println(rs.getTimestamp(i) + " - " + rs.getTimestamp(i).getTimezoneOffset() / 60);
System.out.println(rs.getTime(i) + " - " + rs.getTime(i).getTimezoneOffset() / 60);
System.out.println();
}
}
rs.close();
stmt.close();
conn.close();
}
}
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Bug in storing Timestamp
2005-04-11 12:39 Bug in storing Timestamp Boris Kirzner <borisk@mainsoft.com>
2005-04-14 09:17 ` Re: Bug in storing Timestamp Kris Jurka <books@ejurka.com>
@ 2005-04-21 12:39 ` Boris Kirzner <borisk@mainsoft.com>
2005-04-21 18:27 ` Re: Bug in storing Timestamp Kris Jurka <books@ejurka.com>
0 siblings, 1 reply; 6+ messages in thread
From: Boris Kirzner @ 2005-04-21 12:39 UTC (permalink / raw)
To: Kris Jurka <books@ejurka.com>; +Cc: pgsql-jdbc
Kris Jurka wrote:
>I am not able to reproduce this problem. The attached test case shows a
>problem with storing java.sql.Time into a timetz type because the correct
>offset is not saved, but that's not what you've described. Perhaps it is
>something specific to your timezone?
>
>Kris Jurka
>
Hello Kris
After more investigation I found that the bug I'm talking about can be
reproduced on timestamp column also.
The configuration is as follows :
PostgeSQL runs on WindowsXP that has "Automatically adjust clock for dst
savings" OFF, timezone is (GMT+02:00) Jerusalem
Client runs on WindowsXP that has "Automatically adjust clock for dst
savings" OFF , timezone is (GMT+02:00) Jerusalem
The test stores 2004-08-09 20:30:15.50 timestamp into a table and
immediately fetches it.
Actual result : the value fetched is 2004-08-09 21:30:15.5
Expected result : the value fetched is 2004-08-09 20:30:15.5
Note : if you set client's "Automatically adjust clock for dst savings"
to ON, the test passes.
Attached are test and table sql.
Thanks,
Boris
--
Boris Kirzner
Mainsoft Corporation
http://www.mainsoft.com
Attachments:
PostgreSQL_Timestamp_Test.java (text/java, 3.1K) download
package tests;
import java.sql.*;
import java.util.Properties;
/*
* @(#)PostgreSQL_Timestamp_Test.java 1.0 Created on Apr 21, 2005 2:19:54 PM
*
* Copyright 2002-2003 Mainsoft Corporation. All Rights Reserved.
*
* This software is the proprietary information of Mainsoft Corporation.
* Use is subject to license terms.
*
*/
public class PostgreSQL_Timestamp_Test
{
public static void main(String[] args)
{
Connection connection = connect("xp050", "", "GHTDB", "postgres", "postgres", false);
Timestamp ts = Timestamp.valueOf("2004-08-09 20:30:15.50");
try
{
PreparedStatement pstmt = connection.prepareStatement("delete from borisk_timestamp");
pstmt.execute();
pstmt = connection.prepareStatement("insert into borisk_timestamp values(?)");
pstmt.setTimestamp(1, ts);
pstmt.execute();
pstmt = connection.prepareStatement("select * from borisk_timestamp");
pstmt.execute();
ResultSet rs = pstmt.getResultSet();
rs.next();
Timestamp ts1 = rs.getTimestamp(1);
System.out.println(ts);
System.out.println(ts1);
pstmt = connection.prepareStatement("delete from borisk_timestamp");
pstmt.execute();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
private static Connection connect(String host, String port, String catalog, String user, String pass, boolean trace)
{
String conStr = buildUrl(host, port, catalog);
try
{
activateJDBCDriver(getDriverName());
Properties info = new Properties();
info.put("user", user);
info.put("password", pass);
if (trace)
{
System.out.println("Getting connection to host " + host + " port " + port + " catalog " + catalog);
}
DriverManager.setLoginTimeout(15);
Connection con = DriverManager.getConnection(conStr, info);
if (trace)
{
System.out.println("Connected to host " + host);
}
return con;
}
catch (SQLException e)
{
if (trace)
{
System.out.println("Error connecting to host " + host + " : " + e.getMessage());
}
}
return null;
}
private static void activateJDBCDriver(String _driver)
{
try
{
Class.forName(_driver).newInstance();
}
catch (InstantiationException e)
{
e.printStackTrace();
}
catch (IllegalAccessException e)
{
e.printStackTrace();
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
}
}
private static String buildUrl(String host, String port, String catalog)
{
return "jdbc:postgresql://" + host + "/" + catalog;
}
private static String getDriverName()
{
return "org.postgresql.Driver";
}
}
PostgreSQL_Timestamp_Test.sql (text/plain, 119B) download
CREATE TABLE borisk_timestamp
(
t_timestamp timestamp
)
WITHOUT OIDS;
ALTER TABLE borisk_timestamp OWNER TO postgres;
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Bug in storing Timestamp
2005-04-11 12:39 Bug in storing Timestamp Boris Kirzner <borisk@mainsoft.com>
2005-04-14 09:17 ` Re: Bug in storing Timestamp Kris Jurka <books@ejurka.com>
2005-04-21 12:39 ` Re: Bug in storing Timestamp Boris Kirzner <borisk@mainsoft.com>
@ 2005-04-21 18:27 ` Kris Jurka <books@ejurka.com>
0 siblings, 0 replies; 6+ messages in thread
From: Kris Jurka @ 2005-04-21 18:27 UTC (permalink / raw)
To: Boris Kirzner <borisk@mainsoft.com>; +Cc: pgsql-jdbc
On Thu, 21 Apr 2005, Boris Kirzner wrote:
>
> Kris Jurka wrote:
>
> >I am not able to reproduce this problem. The attached test case shows a
> >problem with storing java.sql.Time into a timetz type because the correct
> >offset is not saved, but that's not what you've described. Perhaps it is
> >something specific to your timezone?
> >
> After more investigation I found that the bug I'm talking about can be
> reproduced on timestamp column also.
>
> The configuration is as follows :
> PostgeSQL runs on WindowsXP that has "Automatically adjust clock for dst
> savings" OFF, timezone is (GMT+02:00) Jerusalem
> Client runs on WindowsXP that has "Automatically adjust clock for dst
> savings" OFF , timezone is (GMT+02:00) Jerusalem
>
> The test stores 2004-08-09 20:30:15.50 timestamp into a table and
> immediately fetches it.
> Actual result : the value fetched is 2004-08-09 21:30:15.5
> Expected result : the value fetched is 2004-08-09 20:30:15.5
This is a known bug in the 8.0 driver and seems different than your
original complaint. Being off by an hour (the difference between the two
timezones) is the expected (and incorrect) behavior that I expected to
see. Your original complaint was off by 20:40 which is an unusual number,
are you still seeing that?
Kris Jurka
^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~2005-04-21 18:27 UTC | newest]
Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-04-11 12:39 Bug in storing Timestamp Boris Kirzner <borisk@mainsoft.com>
2005-04-11 14:57 ` mikael-aronsson <mikael-aronsson@telia.com>
2005-04-11 15:07 ` Tom Lane <tgl@sss.pgh.pa.us>
2005-04-14 09:17 ` Kris Jurka <books@ejurka.com>
2005-04-21 12:39 ` Boris Kirzner <borisk@mainsoft.com>
2005-04-21 18:27 ` Kris Jurka <books@ejurka.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