尝试编写包含 ltree 类型值的实体时,出现以下错误:
column "path" is of type ltree but expression is of type character varying
谷歌搜索那个错误让我在光滑的 Macaddr/Inet 类型的 postgres
Craig Ringer 那里的答案让我走了,虽然创建一个演员文本 - > ltree 没有用,所以我创建了一个演员 varchar - > ltree 如下
CREATE OR REPLACE FUNCTION ltree_invarchar(varchar) RETURNS ltree AS $$
SELECT ltree_in($1::cstring);
$$ LANGUAGE SQL IMMUTABLE;
CREATE CAST (varchar AS ltree) WITH FUNCTION ltree_invarchar(varchar) AS IMPLICIT;
这让我克服了最初的错误,但是现在当我尝试使用 Spring Boot Starter Data JPA 从 Java 插入 ltree 值时,我得到一个长堆栈跟踪,其结尾如下:
Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at position 0
Where: SQL function "ltree_invarchar" statement 1
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2455)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2155)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:288)
at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:430)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:356)
at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:168)
at org.postgresql.jdbc.PgPreparedStatement.executeUpdate(PgPreparedStatement.java:135)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.tomcat.jdbc.pool.StatementFacade$StatementProxy.invoke(StatementFacade.java:114)
at com.sun.proxy.$Proxy120.executeUpdate(Unknown Source)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:204)
... 71 more
我是 postgres 的新手,所以我通过修改我找到的答案中给出的函数来创建上面的函数,但现在我被卡住了。我需要帮助确定什么是语法错误以及如何修复它。