1

I'm using Slick 2.0.0-RC1 with PostgreSQL. How I can compare Timestamp column when I create select query. Suppose I'm trying to make simple query and fetch events with start date after now.

I have column in my table:

  val start: Column[Option[Timestamp]] = column("start")

Query fragment:

val now = new java.sql.Timestamp(new java.util.Date().getTime)

val q = for {
  event <- events
  date <- eventDates if event.id === date.id; if date.start > now
} yield (event, date)

It compiles to something like:

AND (x16."start" >= {ts '2014-01-01 00:00:00.0'}))

And that's seems to be illegal syntax for postgres. How can I make it right?

Cœur
  • 37,241
  • 25
  • 195
  • 267
selfsx
  • 581
  • 7
  • 23

2 Answers2

2

The SQL the OP quotes:

AND (x16."start" >= {ts '2014-01-01 00:00:00.0'}))

is not the actual SQL run by Postgres. It is the JDBC SQL which utilises the ODBC format of:

{ts

If you try to run this SQL directly via psql it will complain of

ERROR: syntax error at or near "{"

I am not sure what the final Postgres SQL will be but I assume JDBC translates it to something like

AND (x16.start > timestamp '2014-01-01 00:00:00.0')

So in fact the SQL reported by Slick is correct.

I just went down this rabbit hole, with the added distraction (but useful) of using https://github.com/tototoshi/slick-joda-mapper instead of direct timestamps. In the end the root cause of my problem was another column and not the timestamp column being wrongly configured.

flurdy
  • 3,782
  • 29
  • 31
1

Sounds like a bug. I submitted a ticket: https://github.com/slick/slick/issues/600 We'll look at it.

Update: We could not reproduce the problem and closed the ticket.

cvogt
  • 11,260
  • 30
  • 46