postgresql语法错误在或附近" EXERCISE_ID"在角色1

时间:2018-03-25 11:17:58

标签: sql postgresql intellij-idea

对于Docker中的postgres我使用一些.sql文件来构建数据库。脚本以正确的顺序连接所有文件。它没有启动Postgres图像,因为存在语法错误。我没有看到它,所以也许你们其中一个人这样做了?

来自IntelliJ的日志:

2018-03-25 11:05:32.628 UTC [73] ERROR:  syntax error at or near "EXERCISE_ID" at character 1
2018-03-25 11:05:32.628 UTC [73] STATEMENT:  EXERCISE_ID SERIAL NOT NULL PRIMARY KEY,
  EXERCISE_NAME VARCHAR(50) NOT NULL,
  EXERCISE_DESCRIPTION VARCHAR(300) NOT NULL,
  EXERCISE_SUBCATEGORY INT NOT NULL REFERENCES TL_CATEGORIES(CATEGORY_ID),
  EXERCISE_DATE_ADD DATE NOT NULL,
  EXERCISE_DATE_CHANGED DATE NOT NULL,
  EXERCISE_LOCATION_URL VARCHAR(300) NOT NULL,
  EXERCISE_STATUS VARCHAR(1) NOT NULL DEFAULT '0'
);
psql:/docker-entrypoint-initdb.d/sqlinit.sql:47: ERROR:  syntax error at or near "EXERCISE_ID"
LINE 1: EXERCISE_ID SERIAL NOT NULL PRIMARY KEY,
    ^

的.sql:

    CREATE TABLE IF NOT EXISTS TL_EXERCISES (
     EXERCISE_ID SERIAL NOT NULL PRIMARY KEY,
     EXERCISE_NAME VARCHAR(50) NOT NULL,
     EXERCISE_DESCRIPTION VARCHAR(300) NOT NULL,
     EXERCISE_SUBCATEGORY INT NOT NULL REFERENCES TL_CATEGORIES(CATEGORY_ID),
     EXERCISE_DATE_ADD DATE NOT NULL,
     EXERCISE_DATE_CHANGED DATE NOT NULL,
     EXERCISE_LOCATION_URL VARCHAR(300) NOT NULL,
     EXERCISE_STATUS VARCHAR(1) NOT NULL DEFAULT '0'
);

IntelliJ的分析未发现任何错误。

如果你能帮助我,我会很高兴。

1 个答案:

答案 0 :(得分:1)

2018-03-25 11:05:32.628 UTC [73] STATEMENT:  EXERCISE_ID SERIAL NOT NULL PRIMARY KEY,
...
LINE 1: EXERCISE_ID SERIAL NOT NULL PRIMARY KEY,

不知何故,你似乎已经从你的sql中丢失了“CREATE TABLE”行。我不知道我有多害怕。