alaisi / postgres-async-driver

Asynchronous PostgreSQL Java driver
Apache License 2.0
287 stars 38 forks source link

Invalid Time Exception While Reading Timestamp #24

Open edalorzo opened 8 years ago

edalorzo commented 8 years ago

Very interesting project. I like it very much. I hope it becomes mature enough to be used in production settings soon.

I found this library the other after playing a bit with the Spring Reactive Playground project.

So I decided to write a small reactive application today. I wrote a very simple program that was intended to read a row from a table in my database. I have a field last_modified which is a timestamp. When I try to read the field doing a row.getTimestamp() I get an SqlException:

com.github.pgasync.SqlException: Invalid time: 2016-07-01 09:00:05-06
    at com.github.pgasync.impl.conversion.TemporalConversions.toTimestamp(TemporalConversions.java:90)
    at com.github.pgasync.impl.conversion.DataConverter.toTimestamp(DataConverter.java:63)
    at com.github.pgasync.impl.PgRow.getTimestamp(PgRow.java:174)
...

The problem seems to be located in the TemporalConversions.toTimstamp() method as you can see. It appears that the default configuration for timestamp is not working for me out of the box.

My date format seems to be yyyy-MM-dd HH:mm:ssX but the one given in the toTimestamp() is yyyy-MM-dd HH:mm:ss.SSS and this breaks my code.

Not sure why the driver chooses that particular date time format, but I suppose it does not apply to all PostgreSQL configurations.

I wonder if the format can be configured somehow without I having to write my own Timestamp converter, but otherwise you may want to look into this issue or perhaps offer a way to configure the format either globally or in the toTimestamp() function.

To make things worse I cannot retrieve the value neither as a string or as a long without getting an "unsupported conversion exception", so basically I cannot retrieve the record from the database simply because my timestamp format is different.

alaisi commented 8 years ago

Thanks for the bug report. Can you verify that the exception occurs when using version 0.9 of the library?