首先,我收到了这个错误:
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)
...
Run Code Online (Sandbox Code Playgroud)
在谷歌搜索一段时间后,我认为我应该将列类型从 oid 更改为 bytea。我在 UI pgAdmin 中尝试了这个:
ALTER TABLE theTableName
ALTER COLUMN xxxx TYPE bytea
Run Code Online (Sandbox Code Playgroud)
但我得到了错误:
ERROR: column "xxxx" cannot be cast automatically to type bytea
HINT: You might need to specify "USING xxxx::bytea".
SQL state: 42804
Run Code Online (Sandbox Code Playgroud)
然后我尝试:
ALTER TABLE theTableName
ALTER COLUMN xxxx TYPE bytea USING xxxx::bytea
Run Code Online (Sandbox Code Playgroud)
我收到了这个错误:
ERROR: cannot cast type oid to bytea
LINE 2: ALTER COLUMN xxxx TYPE bytea USING xxxx::bytea
^
SQL state: 42846
Character: 88
Run Code Online (Sandbox Code Playgroud)
请问如何解决这个问题?非常感谢!
投射到TEXT然后到BYTEA:
ALTER TABLE theTableName
ALTER COLUMN xxxx TYPE bytea USING xxxx::TEXT::BYTEA
Run Code Online (Sandbox Code Playgroud)
警告
请注意,这不会神奇地迁移任何数据!因此,pg_largobject由存储在 oid 列中的值引用的大对象不会复制到theTableName表中。只在空表上运行这个,或者如果你能承受丢失大对象。