在 JPA 查询中将日期从日期时间转换为文本
Convert date from datetime to text in JPA Query
我想从 table 中查找数据,使用日期上的“赞”。执行此命令时我得到了正确的结果
SELECT * FROM transaction_history th WHERE date(th.transaction_date) LIKE '%7%';
但是在 JPA 本地查询中我得到了这样的错误
Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at or near ":"
任何帮助将不胜感激
根据 postgresql official doc,首先你必须将日期列转换为字符串,然后 运行 你的 select 查询
to_char(timestamp, text) convert time stamp to string
to_char(current_timestamp, 'HH12:MI:SS')
应该是这样的:
SELECT * FROM transaction_history th WHERE to_char(th.transaction_date, 'HH12:MI:SS') LIKE '%7%';
我想从 table 中查找数据,使用日期上的“赞”。执行此命令时我得到了正确的结果
SELECT * FROM transaction_history th WHERE date(th.transaction_date) LIKE '%7%';
但是在 JPA 本地查询中我得到了这样的错误
Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at or near ":"
任何帮助将不胜感激
根据 postgresql official doc,首先你必须将日期列转换为字符串,然后 运行 你的 select 查询
to_char(timestamp, text) convert time stamp to string to_char(current_timestamp, 'HH12:MI:SS')
应该是这样的:
SELECT * FROM transaction_history th WHERE to_char(th.transaction_date, 'HH12:MI:SS') LIKE '%7%';