英文:
Can't rename table to the same name as type in postgres
问题
无法执行需要将表重命名为已存在的类型相同名称的SQL查询。在PostgreSQL中,我没有找到关于不同对象具有相同名称的任何规则或注释。
CREATE TYPE ratings.processed_sport_bet AS ENUM ('sport_bet_created', 'sport_bet_resulted');
ALTER TABLE ratings.processed_sport_bet_resulted RENAME TO processed_sport_bet;
获得错误信息:
[42710] ERROR: 类型 "processed_sport_bet" 已经存在
英文:
I can't execute sql query, that has to rename the table to the same name as type, that already exists. I have not found any rules or comments about the same name for different things in postgres.
CREATE TYPE ratings.processed_sport_bet AS ENUM ('sport_bet_created', 'sport_bet_resulted');
ALTER TABLE ratings.processed_sport_bet_resulted RENAME TO processed_sport_bet;
Get the error
[42710] ERROR: type "processed_sport_bet" already exists
答案1
得分: 2
当创建表时,PostgreSQL会自动创建一个与表的行结构同名的类型。当重命名表时,相关联的类型也会被重命名。如果另一个类型已经使用了相同的名称,那么会引发异常。
英文:
When a table is created, PostgreSQL automatically creates a type for the table's row structure, with the same name as the table. When renaming the table, the associated type is also renamed. If another type already has that name, then an exception is raised.
答案2
得分: 0
CREATE TABLE 会自动创建一个表示表中一行对应的复合类型的数据类型。因此,在同一模式中,表不能与任何现有数据类型具有相同的名称。参考链接:https://www.postgresql.org/docs/15/sql-createtable.html
英文:
CREATE TABLE also automatically creates a data type that represents the composite type corresponding to one row of the table. Therefore, tables cannot have the same name as any existing data type in the same schema. For ref: https://www.postgresql.org/docs/15/sql-createtable.html
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论