I am trying to create a table that was dropped previously.
But when I do the CREATE TABLE A ..
. I am getting below error:
Relation 'A' already exists.
I verified doing SELECT * FROM A
, but then I got another error:
Relation 'A' does not exists.
I already tried to find it in \dS+
listing all relations, and it is not there.
To complicate this, I have tested this by creating this table in another database and I got the same error. I am thinking that could be an error when this table was dropped. Any ideas?
Here is the code: I'm using a generated code from Power SQL. I have the same error without using the sequence. It just works when I change the name and in this case I can not do that.
CREATE SEQUENCE csd_relationship_csd_relationship_id_seq;
CREATE TABLE csd_relationship (
csd_relationship_id INTEGER NOT NULL DEFAULT nextval('csd_relationship_csd_relationship_id_seq'::regclass),
type_id INTEGER NOT NULL,
object_id INTEGER NOT NULL,
CONSTRAINT csd_relationship PRIMARY KEY (csd_relationship_id)
);
You cannot create a table with a name that is identical to an existing table or view in the cluster. To modify an existing table, use
ALTER TABLE
(link), or to drop all data currently in the table and create an empty table with the desired schema, issueDROP TABLE
beforeCREATE TABLE
.It could be that the sequence you are creating is the culprit. In PostgreSQL, sequences are implemented as a table with a particular set of columns. If you already have the sequence defined, you should probably skip creating it. Unfortunately, there's no equivalent in
CREATE SEQUENCE
to theIF NOT EXISTS
construct available inCREATE TABLE
. By the looks of it, you might be creating your schema unconditionally, anyways, so it's reasonable to usebefore the rest of your schema update; In case it isn't obvious, This will delete all of the data in the
csd_relationship
table, if there is any