postgresql - 我正在尝试使用 lpad SQL 函数,但它抛出 lpad(text) 不存在
问题描述
我正在尝试使用 lpad 函数,但它抛出 lpad(text) 在 java 中不存在,但在 Postgres DB 中运行查询时它工作得非常好。
我使用了以下查询,
SELECT *
FROM A
where extract( epoch from to_timestamp(LPAD(CAST (executedDate AS text),8,'0') || LPAD(CAST (executeTime AS text),6,'0'),'YYYYMMDDHH24MISS')) < :ValueinSecounds
这里 executeDate(int4 datatype) 和 executeTime(int4 datatype) 值以 GMT 格式插入到表中。
我需要连接 executeDate 和 executeTime 以获取 KTI 时间戳(以秒为单位)。
由于一些现有记录在执行时间中有 5 位数字,因此使用了 LPAD 功能。
这是抛出以下异常:
Caused by: org.postgresql.util.PSQLException: ERROR: function lpad(text) does not exist
Hint: No function matches the given name and argument types. You might need to add explicit type casts.
Position: 1381
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2533) ~[postgresql-42.2.12.jar:42.2.12]
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2268) ~[postgresql-42.2.12.jar:42.2.12]
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:313) ~[postgresql-42.2.12.jar:42.2.12]
at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:448) ~[postgresql-42.2.12.jar:42.2.12]
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:369) ~[postgresql-42.2.12.jar:42.2.12]
at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:159) ~[postgresql-42.2.12.jar:42.2.12]
at org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.java:109) ~[postgresql-42.2.12.jar:42.2.12]
at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeQuery(ProxyPreparedStatement.java:52) ~[HikariCP-3.4.2.jar:?]
at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeQuery(HikariProxyPreparedStatement.java) ~[HikariCP-3.4.2.jar:?]
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:57) ~[hibernate-core-5.4.10.Final.jar:5.4.10.Final]
at org.hibernate.loader.Loader.getResultSet(Loader.java:2292) ~[hibernate-core-5.4.10.Final.jar:5.4.10.Final]
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:2050) ~[hibernate-core-5.4.10.Final.jar:5.4.10.Final]
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:2012) ~[hibernate-core-5.4.10.Final.jar:5.4.10.Final]
at org.hibernate.loader.Loader.doQuery(Loader.java:953) ~[hibernate-core-5.4.10.Final.jar:5.4.10.Final]
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:354) ~[hibernate-core-5.4.10.Final.jar:5.4.10.Final]
at org.hibernate.loader.Loader.doList(Loader.java:2815) ~[hibernate-core-5.4.10.Final.jar:5.4.10.Final]
at org.hibernate.loader.Loader.doList(Loader.java:2797) ~[hibernate-core-5.4.10.Final.jar:5.4.10.Final]
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2629) ~[hibernate-core-5.4.10.Final.jar:5.4.10.Final]
at org.hibernate.loader.Loader.list(Loader.java:2624) ~[hibernate-core-5.4.10.Final.jar:5.4.10.Final]
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:506) ~[hibernate-core-5.4.10.Final.jar:5.4.10.Final]
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:396) ~[hibernate-core-5.4.10.Final.jar:5.4.10.Final]
at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:219) ~[hibernate-core-5.4.10.Final.jar:5.4.10.Final]
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1396) ~[hibernate-core-5.4.10.Final.jar:5.4.10.Final]
at org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1558) ~[hibernate-core-5.4.10.Final.jar:5.4.10.Final]
at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1526) ~[hibernate-core-5.4.10.Final.jar:5.4.10.Final]
... 40 more***
解决方案
推荐阅读
- javascript - 无法在 onClick 触发器中过滤来自 ajax 调用的 Json 数据
- postgresql - 根据列匹配条件过滤 PostgreSQL 表中的行
- r - 如何使用 R 中的 ggtree 链接倒置圆形系统发育树中的几个尖端节点
- python - 从没有 to_dict 的 pandas df 生成字典的最快方法
- typescript - 我应该为打字稿中的 dynamodb 流事件使用什么类型?
- database - 如果我不在查询中使用标签,这会降低基数吗?
- c++ - 为什么 rk4.do_step 在 C++ 中不输出初始条件?
- reactjs - 如何将 React 构建文件添加到现有 JSP 项目中
- mysql - 错误 1064 - 触发器创建期间“附近的语法错误”
- python - 我怎样才能知道如何获得正确的pk?