skip to Main Content

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

2

Answers


  1. 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.

    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search