I am using myBatis through annotations to fetch data from my server. Trying to get the data n days old, the annotation :
@Select("SELECT o.title from user_order o where current_date - date_trunc('day', o.dateoforder) < '#{n} days'")
ArrayList<OrderRecord> getOrderHistory(@Param("n") int n);
returns error:
The column index is out of range: 1, number of columns: 0. Error querying database. Cause: org.postgresql.util.PSQLException: The column index is out of range: 1, number of columns: 0.
Also,
@Select("SELECT o.title from user_order o where current_date - date_trunc('day', o.dateoforder) < #{n}")
ArrayList<OrderRecord> getOrderHistory(@Param("n") String n);
produces the similar error when n is something like "5 days".
What data-type is being expected?
I am using PostgreSQL.
Mybatis is expecting an interval parameter and cannot cast the integer or String into it automatically.
An object of the type PGInterval needs to be passed.
PGInterval pginterval = new PGInterval("5 days");
and the annotation must be:
@Select("SELECT o.title from user_order o where current_date - date_trunc('day', o.dateoforder) < #{n}")
ArrayList<OrderRecord> getOrderHistory(@Param("n") PGInterval n);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With