Postgres SQL语法错误靠近隐形'参考&#39 ;?

时间:2017-09-29 11:26:49

标签: sql postgresql syntax-error

我正在尝试使用以下代码创建两个表。

CREATE TABLE assessments (
  id INT UNIQUE PRIMARY KEY,
  name VARCHAR(100),
  type VARCHAR(10),
  total_points NUMERIC,
  weight NUMERIC
  CHECK(weight >= 0)
  CHECK(weight <= 100),
  due_date DATE,
  section_id INT REFERENCES sections(id)
);

CREATE TABLE enrollment_assessments (
  id INT UNIQUE PRIMARY KEY REFERENCES enrollments(id),
  assignment_id REFERENCES assignments(id),
  assessment_type REFERENCES assessments(type),
  points NUMERIC
    CHECK (points >= 0)
    CHECK (points <-100),
);

然而,我收到错误:

  

[代码:,SQL状态:42601]错误:语法错误在或附近   &#34;参考&#34;位置:112

这说错误是在第一行代码附近?我根本不理解这个错误。

2 个答案:

答案 0 :(得分:0)

我不喜欢这部分中的逗号:

CHECK (points >= 0)
CHECK (points <-100),

答案 1 :(得分:0)

您错过了数据类型,并且必须删除额外的逗号:

 CREATE TABLE enrollment_assessments (
  id INT UNIQUE PRIMARY KEY REFERENCES enrollments(id),
  assignment_id INT REFERENCES assignments(id),
  assessment_type VARCHAR(10) REFERENCES assessments(type),
  points NUMERIC
    CHECK (points >= 0)
    CHECK (points <-100)
);