postgres关系中的ALTER TYPE错误不存在 [英] Error on ALTER TYPE in postgres relation does not exist

查看:228
本文介绍了postgres关系中的ALTER TYPE错误不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用以下内容:

CREATE TYPE user_types AS ENUM ('it', 'accounting', 'processes');

CREATE TABLE my_users
(
    my_user_id integer NOT NULL,
    my_user_name text NOT NULL,
    my_user_type user_types
)

我想更改一种用户类型:

I want to change one of the user types:

ALTER TYPE user_types RENAME ATTRIBUTE it TO softwaredev CASCADE;

我遇到错误:

ERROR: relation "user_types" does not exist
SQL state: 42P01

我尝试添加引号和反引号,但这没有帮助。我在这里写下的示例不是确切的代码,我的类型有31个字符,但我认为我的类型的长度不是问题。

I tried adding quotes and backticks but that didn't help. The example I wrote down here is not the exact code, my type has 31 characters, but I don't think the length of my type is the issue.

我' m使用postgres版本9.6.2

I'm using postgres version 9.6.2

推荐答案

更改类型...重命名属性仅适用于复合类型,不适用于 ENUM 类型。

ALTER TYPE ... RENAME ATTRIBUTE only works for composite types, not for ENUM types.

虽然可以添加新条目改成这样的类型( ALTER TYPE ... ADD VALUE'new_value'),没有支持的方法来删除或重命名枚举条目。

While there is a way to add new entries to such a type (ALTER TYPE ... ADD VALUE 'new_value'), there is no supported way to remove or rename an enumeration entry.

如果您不怕弄乱目录,可以尝试以超级用户身份使用:

If you are not afraid to mess with the catalogs, you can try as superuser:

UPDATE pg_enum
SET enumlabel = 'softwaredev'
WHERE enumtypid = 'user_types'::regtype
  AND enumlabel = 'it';

从PostgreSQL v10开始,您可以使用

From PostgreSQL v10 on, you can use

ALTER TYPE ... RENAME VALUE ... TO ...

这篇关于postgres关系中的ALTER TYPE错误不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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