PostgreSQL Error: Relation already exists

后端 未结 8 1830
暖寄归人
暖寄归人 2020-12-05 12:37

I am trying to create a table that was dropped previously.

But when I do the CREATE TABLE A ... I am getting below error:

Rela

8条回答
  •  半阙折子戏
    2020-12-05 13:10

    There should be no single quotes here 'A'. Single quotes are for string literals: 'some value'.
    Either use double quotes to preserve the upper case spelling of "A":

    CREATE TABLE "A" ...
    

    Or don't use quotes at all:

    CREATE TABLE A ...
    

    which is identical to

    CREATE TABLE a ...
    

    because all unquoted identifiers are folded to lower case automatically in PostgreSQL.


    You could avoid problems with the index name completely by using simpler syntax:

    CREATE TABLE csd_relationship (
        csd_relationship_id serial PRIMARY KEY,
        type_id integer NOT NULL,
        object_id integer NOT NULL
    );
    

    Does the same as your original query, only it avoids naming conflicts automatically. It picks the next free identifier automatically. More about the serial type in the manual.

提交回复
热议问题