Re: JDBC - Prepared statements and PostgreSql Time/Date operations

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: JDBC - Prepared statements and PostgreSql Time/Date operations
Дата
Msg-id 3020.1179523605@sss.pgh.pa.us
обсуждение исходный текст
Ответ на JDBC - Prepared statements and PostgreSql Time/Date operations  ("Jan Bilek" <bilekj@gmail.com>)
Список pgsql-general
"Jan Bilek" <bilekj@gmail.com> writes:
> I would like to use this query in java PreparedStatement, where age of a =
> row would be one of its parameters:

> PreparedStatement could look like this:
> select * from mytable where creation_time > (CURRENT_TIMESTAMP - ?)

> But nothing works with PreparedStatements!
> I tried to set whole interval strings "interval '7 days'" as a parameter
> I tried to set time strings '7 days' as a parameter
> I tried to use BigDecimal as a parameter...

I'm not sure that Java has a type corresponding to "interval".  Instead
use number-times-interval multiplication:

    ... creation_time > (CURRENT_TIMESTAMP - ? * interval '1 day')

The parameter is now of plain integer or float type.

            regards, tom lane

В списке pgsql-general по дате отправления:

Предыдущее
От: Reece Hart
Дата:
Сообщение: Re: Random Sample
Следующее
От: "Jan Bilek"
Дата:
Сообщение: Re: JDBC - Prepared statements and PostgreSql Time/Date operations