Skip to content
Advertisement

Cannot create a table due to naming conflict

I am trying to create a table in my database and it gives me the following error.

Then I thought that the table must exist so I ran the following query:

But could not find anything. Then I tried:

Any idea how to sort this?

i am tying to rename the type by

and getting the error.

Advertisement

Answer

Postgres creates a composite (row) type of the same name for every table. That’s why the error message mentions “type”, not “table”. Effectively, a table name cannot conflict with this list from the manual on pg_class:

r = ordinary table, i = index, S = sequence, t = TOAST table, v = view, m = materialized view, c = composite type, f = foreign table, p = partitioned table, I = partitioned index

Bold emphasis mine. Accordingly, you can find any conflicting entry with this query:

This covers all possible competitors, not just types. Note that the same name can exist multiple times in multiple schemas – but not in the same schema.

Cure

If you find a conflicting composite type, you can rename or drop it to make way – if you don’t need it!

Be sure that the schema of the type is the first match in your search path or schema-qualify the name. I added the schema to the query above. Like:

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement