Re: JDBC - Prepared statements and PostgreSql Time/Date operations - Mailing list pgsql-general

From Jan Bilek
Subject Re: JDBC - Prepared statements and PostgreSql Time/Date operations
Date
Msg-id 002201c7999a$17f89990$0100a8c0@ook
Whole thread Raw
In response to JDBC - Prepared statements and PostgreSql Time/Date operations  ("Jan Bilek" <bilekj@gmail.com>)
List pgsql-general
Got it!
> "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')

Integer-interval multiplication is the way!!!
Many thanks for quick help.

(Java seems not to have oracle/postgre interval type)

>
> The parameter is now of plain integer or float type.
>
> regards, tom lane


pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: JDBC - Prepared statements and PostgreSql Time/Date operations
Next
From: "Dann Corbit"
Date:
Subject: Re: UNION help