mauricio / postgresql-async

Async, Netty based, database drivers for PostgreSQL and MySQL written in Scala
Apache License 2.0
1.43k stars 222 forks source link

Postgresql 9.5 Timestamp with time zone #240

Open ZenLiuCN opened 6 years ago

ZenLiuCN commented 6 years ago

I'm using vertx 3.5.0 with postgresqlasync_2.12:0.2.21 insert into postgresql with Instant.now(),after then sometimes will got

java.lang.IllegalArgumentException: Invalid format: "2017-12-22 10:19:38+08" is malformed at "+08"
    at org.joda.time.format.DateTimeFormatter.parseDateTime(DateTimeFormatter.java:945)
    at com.github.mauricio.async.db.postgresql.column.PostgreSQLTimestampEncoderDecoder$.decode(PostgreSQLTimestampEncoderDecoder.scala:71)
    at com.github.mauricio.async.db.postgresql.column.PostgreSQLColumnDecoderRegistry.decode(PostgreSQLColumnDecoderRegistry.scala:52)
    at com.github.mauricio.async.db.postgresql.PostgreSQLConnection.onDataRow(PostgreSQLConnection.scala:203)
    at com.github.mauricio.async.db.postgresql.codec.PostgreSQLConnectionHandler.channelRead0(PostgreSQLConnectionHandler.scala:203)
    at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105)

i think it's because Instant.now() is with zone have zero millseconds(like 2017-01-01T00:00:00+8) finally i use

fun String.toPgTimeParse():String="to_char($this at time zone 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS\"Z\"')"

to convert it before get from database

manorsuperman commented 6 years ago

I encountered this problem too.

codepitbull commented 6 years ago

I just provided a PR to fix this issue: https://github.com/mauricio/postgresql-async/pull/255