Re: [SQL] What JDBC datatype can be used for DATETIME ?

From: Herouth Maoz <herouth(at)oumail(dot)openu(dot)ac(dot)il>
To: jon(at)it-konsulenterne(dot)dk (Jon Windfeld Bundesen), pgsql-sql(at)postgreSQL(dot)org
Subject: Re: [SQL] What JDBC datatype can be used for DATETIME ?
Date: 1999-08-22 12:22:39
Message-ID: l03130300b3e598a52436@[147.233.159.109]
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

At 18:42 +0300 on 19/08/1999, Jon Windfeld Bundesen wrote:

>
> When i try using ResultSet.getTimestamp() instead, i also get an error:
> java.lang.NumberFormatException: 1999 CEST
> at java.lang.Float.<init>(Float.java)
> at postgresql.ResultSet.getTimestamp(ResultSet.java:455)
> at TestDate.main(TestDate.java:32)
>
> I CAN use getString(), but i'd like to get a real Date object, not just
> a String. Can anyone help ?

Basically, Java recognises the string structure sent to it by PostgreSQL's
timestamp. Since the string structure sent by datetime is different by
default, it fails to interpret is as a datetime:

testing=> SELECT '22-aug-1999 15:10'::timestamp;
?column?
----------------------
1999-08-22 15:10:00+03
(1 row)

testing=> SELECT '22-aug-1999 15:10'::datetime;
?column?
----------------------------
Sun Aug 22 15:10:00 1999 IDT
(1 row)

The former is the ISO style. One may change the datestyle to get the same
result out of datetime, but this is not recommended within the context of
JDBC, because the JDBC interpretation functions set it themselves, if I'm
not mistaken:

testing=> SET DATESTYLE='iso';
SET VARIABLE
testing=> SELECT '22-aug-1999 15:10'::datetime;
?column?
----------------------
1999-08-22 15:10:00+03
(1 row)

Another solution that achieves the same goal is to make sure all the fields
you select from your tables are in timestamp rather than datetime. Either
have that in your table (but this has a problem with indexing), or just
change your selects. Instead of

SELECT dt FROM foo;

Use

SELECT timestamp( dt ) FROM foo;

In 6.4 there is a bug in this, so you can define your own function for the
conversion. Or you can use abstime(dt) instead. The conversion function
would be:

testing=> CREATE FUNCTION dt_timestamp( datetime ) RETURNS timestamp
testing-> AS 'SELECT timestamp_in( datetime_out( $1 ) )
testing'> WHERE $1 IS NOT NULL'
testing-> LANGUAGE 'sql';

Herouth

--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Herouth Maoz 1999-08-22 12:44:37 Re: [SQL] Counting the number of distinct rows returned
Previous Message Mihai Barbos 1999-08-21 15:01:02 Re: [SQL] UNIQUE constraint