PostgreSQL timestamp parameter: could not determine data type of parameter $1

0

I'm really struggling to get my query to work against my PostgreSQL database. Essentially, my query can be delimited by a timestamp, a parameter that the user can input, but which can also be empty. If no timestamp is provided, I must tell PostgreSQL to use '-infinity' instead. I tried writing the conditional statement below, but I get the error 'Could not determine data type of parameter $1' Can anyone tell me what's wrong with my query?

SELECT *
FROM log
WHERE CASE
  WHEN $P{timestampFrom} IS NULL THEN TIMESTAMP >= '-infinity'
  ELSE TIMESTAMP >= $P{timestampFrom}
  END

$P{timestampFrom} is a sql.Timestamp parameter.

jean.sebastien.lemay's picture
Joined: Dec 30 2015 - 7:02pm
Last seen: 3 years 10 months ago

1 Answer:

1

OK, I realised it was a PostgreSQL error. The solution is to force PostgreSQL to interpret the parameter as a timestamp

SELECT *
FROM log
WHERE CASE
  WHEN $P{timestampFrom}::TIMESTAMP IS NULL THEN TIMESTAMP >= '-infinity'
  ELSE TIMESTAMP >= $P{timestampFrom}
  END
jean.sebastien.lemay's picture
Joined: Dec 30 2015 - 7:02pm
Last seen: 3 years 10 months ago
Feedback
randomness