“on”或其附近的语法错误

时间:2013-07-14 10:55:14

标签: sql postgresql postgresql-8.4

在PostgreSQL 8.4.13中为什么我会得到语法错误

ERROR:  syntax error at or near "on" 
LINE: ... references balkan_users(id) check (id <> author) on delete ...

以下两个陈述?

create table balkan_users (
        id varchar(32) primary key,
        first_name varchar(64) not null,
        last_name varchar(64),
        female boolean,
        avatar varchar(128),
        city varchar(64),
        mobile varchar(64),
        login timestamp default current_timestamp,
        logout timestamp,
        last_ip inet,
        vip timestamp,
        mail varchar(256),
        green integer,
        red integer,
        medals integer not null default 0
);

create table balkan_rep (
        rep_id serial,
        id varchar(32) references balkan_users(id) check (id <> author) on delete cascade,
        author varchar(32) references balkan_users(id) on delete cascade,
        author_ip inet,
        nice boolean,
        about varchar(256),
        stamp timestamp default current_timestamp,
        primary key(id, author);
);

我还准备了an SQLFiddle来演示我的问题。

1 个答案:

答案 0 :(得分:3)

错误 :“on”或附近的语法错误:

check

之后移动on delete cascade
id varchar(32) references balkan_users(id) on delete cascade check (id <> author),

错误 :输入结束时出现语法错误:

删除最后一列primary key(id, author);

上的分号

SQL Fiddle