From: Kris Jurka <books@ejurka.com>
To: Mario Splivalo <mario.splivalo@mobart.hr>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: Storing and retreiving infinity timestamp values from
Date: Wed, 27 Sep 2006 13:37:43 -0500 (EST)
Message-ID: <Pine.BSO.4.63.0609271315440.6334@leary2.csoft.net> (raw)
In-Reply-To: <1159310836.18217.5.camel@localhost.localdomain>
References: <1159310836.18217.5.camel@localhost.localdomain>
On Wed, 27 Sep 2006, Mario Splivalo wrote:
> I have read some posts on this mailinglist concerning the infinity value
> of the timestamp data type, where it was stated that an exception is
> thrown when one attempts to read infinity value. Now, on the postgresql
> jdbc there is an entry in TODO list wich mentions adding handling of
> 'infinity' values to the jdbc documentation.
>
> Is it possible for someone to post some code here for reading/storing
> infinity timestamp values to and from postgres database?
>
See attached. We use special constants to indicate infinity because Java
has no equivalent. Looking at this test output, the displayed value of
our negative infinity value looks a little suspect and I suspect there's
something timezone dependent going on there. Any change to that shouldn't
affect your code, just the constants value.
Kris Jurka
Attachments:InfTS.java (text/plain, 1.1K) download
import java.sql.*;
import org.postgresql.PGStatement;
public class InfTS {
public static void main(String args[]) throws Exception {
Class.forName("org.postgresql.Driver");
Connection conn = DriverManager.getConnection("jdbc:postgresql://localhost:5432/jurka","jurka","");
Statement stmt = conn.createStatement();
stmt.execute("CREATE TEMP TABLE infts (a timestamptz)");
PreparedStatement pstmt = conn.prepareStatement("INSERT INTO infts VALUES (?)");
pstmt.setTimestamp(1, new Timestamp(PGStatement.DATE_POSITIVE_INFINITY));
pstmt.executeUpdate();
pstmt.setTimestamp(1, new Timestamp(PGStatement.DATE_NEGATIVE_INFINITY));
pstmt.executeUpdate();
ResultSet rs = stmt.executeQuery("SELECT * FROM infts");
while (rs.next()) {
System.out.println(rs.getString(1));
System.out.println("Is +inf: " + (rs.getTimestamp(1).getTime() == PGStatement.DATE_POSITIVE_INFINITY));
System.out.println("Is -inf: " + (rs.getTimestamp(1).getTime() == PGStatement.DATE_NEGATIVE_INFINITY));
System.out.println(rs.getTimestamp(1));
}
}
}
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, mario.splivalo@mobart.hr
Subject: Re: Storing and retreiving infinity timestamp values from
In-Reply-To: <Pine.BSO.4.63.0609271315440.6334@leary2.csoft.net>
References: <1159310836.18217.5.camel@localhost.localdomain> <Pine.BSO.4.63.0609271315440.6334@leary2.csoft.net>
* 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