简体   繁体   English

更改 postgres 中的列类型不起作用

[英]change the type of column in postgres not working

I have a column of type object, and i need to make it from another object type, (the table is empty )我有一列对象类型,我需要从另一个对象类型中创建它,(表是空的)

i tried to do :我试着做:

ALTER TABLE invoice_history ALTER COLUMN invoice_info TYPE invoice USING (trim(invoice_info)::invoice);

ERROR: function pg_catalog.btrim(invoice_item) does not exist LINE 1: ...ory ALTER COLUMN invoice_info TYPE invoice USING (trim(invoi... ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts.错误:函数 pg_catalog.btrim(invoice_item) 不存在第 1 行:...ory ALTER COLUMN invoice_info TYPE invoice USING (trim(invoi... ^ 提示:没有函数匹配给定的名称和参数类型。您可能需要添加显式类型转换。

and :和 :

ALTER TABLE invoice_history 
    ALTER COLUMN invoice_info TYPE invoice USING (invoice_info::invoice)

given this error :鉴于此错误:

ERROR: cannot cast type invoice_item to invoice LINE 2: ...UMN invoice_info TYPE invoice USING (invoice_info::invoice...错误:无法将类型 invoice_item 转换为发票第 2 行:...UMN invoice_info TYPE invoice USING (invoice_info::invoice...

what i should do ?我该做什么 ? and how can it changed ?它怎么能改变?

If the table is empty (or you do not care about the column value conversion) use just null , eg:如果表为空(或者您不关心列值转换),请仅使用null ,例如:

alter table invoice_history 
    alter invoice_info type invoice using null;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM