首先,我遇到此错误:
org.postgresql.util.PSQLException: ERROR: column xxxx is of type oid but expression is of type bytea
Hint: You will need to rewrite or cast the expression.
Position: 318
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2182)
...
经过一段时间的搜索,我认为我应该将列类型从oid更改为bytea。我在用户界面pgAdmin中尝试过此操作:
ALTER TABLE theTableName
ALTER COLUMN xxxx TYPE bytea
但是我得到了错误:
ERROR: column "xxxx" cannot be cast automatically to type bytea
HINT: You might need to specify "USING xxxx::bytea".
SQL state: 42804
然后我尝试:
ALTER TABLE theTableName
ALTER COLUMN xxxx TYPE bytea USING xxxx::bytea
我得到了这个错误:
ERROR: cannot cast type oid to bytea
LINE 2: ALTER COLUMN xxxx TYPE bytea USING xxxx::bytea
^
SQL state: 42846
Character: 88
请问该如何解决?非常感谢!
答案 0 :(得分:3)
先投射到TEXT
,然后投射到BYTEA
:
ALTER TABLE theTableName
ALTER COLUMN xxxx TYPE bytea USING xxxx::TEXT::BYTEA