重命名枚举值导致“类型关系未找到”。 [英] Renaming an enum value results in "Type Relation Not found"

查看:86
本文介绍了重命名枚举值导致“类型关系未找到”。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用查询更新TYPE:

I am trying to update TYPE with query:

ALTER TYPE public.enum_subscription_sub_frequency RENAME ATTRIBUTE "BI-WEEKLY" TO "BI_WEEKLY";

但是它给了我错误错误:关系 public.enum_subscription_sub_frequency没有存在但类型存在。

But it give me error ERROR: relation "public.enum_subscription_sub_frequency" does not exist but type is exist.

请帮我完成此操作。

屏幕:

得到的答案:

ALTER TYPE public.enum_subscription_sub_frequency RENAME VALUE 'BI-MONTHLY' TO 'BI_MONTHLY';

但是我还需要更改TYPE的多个值?

but i also need to alter multiple value of a TYPE?

推荐答案

仅从Postgres 10开始才支持重命名枚举值。

Renaming a value of an enum is only supported starting with Postgres 10.

已记录在手册中,您必须使用重命名值,而不是重命名属性来重命名枚举的值。

As documented in the manual you have to use rename VALUE, not rename attribute to rename the value of an enum.

枚举值也是字符串常量,而不是标识符。因此,您需要将它们用单引号引起来,而不是将双引号引起来:

Enums values are also string constants, not identifiers. Therefore you need to enclose them in single quotes, not double quotes:

ALTER TYPE public.enum_subscription_sub_frequency RENAME VALUE 'BI-WEEKLY' TO 'BI_WEEKLY';






如果您想知道为什么会得到类型。 ..不存在,语法错误:


If you wonder why you get a "type ... does not exist" error with the wrong syntax:

当您使用选项重命名属性时,表明应该更改常规对象类型,以便Postgres寻找真实对象类型。

When you use the option RENAME ATTRIBUTE this indicates that a "regular" object type should be changed, so Postgres looks for an "real" object type.

但是枚举类型不是对象类型,因此Postgres抱怨 xyz类型不存在,而不是语法错误。

But an "enum type" is not an "object type" and therefor Postgres complains about "type xyz does not exist", rather than a syntax error.

这篇关于重命名枚举值导致“类型关系未找到”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆