pg.ddx.io pgsql-jdbc@postgresql.org mailing list archivehelp / color / mirror / Atom feed
Storing and retreiving infinity timestamp values from postgres database 2+ messages / 2 participants [nested] [flat]
* Storing and retreiving infinity timestamp values from postgres database @ 2006-09-26 22:47 Mario Splivalo <mario.splivalo@mobart.hr> 0 siblings, 1 reply; 2+ messages in thread From: Mario Splivalo @ 2006-09-26 22:47 UTC (permalink / raw) To: pgsql-jdbc 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? I'm using postgres 8.1 with latest JDBC drivers, and from the postgres JDBC web page can be concluded that the infinity support has been added to the driver. Mario -- Mario Splivalo Mob-Art mario.splivalo@mobart.hr "I can do it quick, I can do it cheap, I can do it well. Pick any two." ^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Storing and retreiving infinity timestamp values from @ 2006-09-27 18:37 Kris Jurka <books@ejurka.com> parent: Mario Splivalo <mario.splivalo@mobart.hr> 0 siblings, 0 replies; 2+ messages in thread From: Kris Jurka @ 2006-09-27 18:37 UTC (permalink / raw) To: Mario Splivalo <mario.splivalo@mobart.hr>; +Cc: pgsql-jdbc 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:^ permalink raw reply [nested|flat] 2+ messages in threadInfTS.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)); } } }
end of thread, other threads:[~2006-09-27 18:37 UTC | newest] Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2006-09-26 22:47 Storing and retreiving infinity timestamp values from postgres database Mario Splivalo <mario.splivalo@mobart.hr> 2006-09-27 18:37 ` Re: Storing and retreiving infinity timestamp values from 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