Home > Blockchain >  postgreSQL syntax error at or near "foreign"
postgreSQL syntax error at or near "foreign"

Time:05-03

I get the following error of "syntax error at or near "foreign"" when trying to create kurinys table. Might be a silly mistake but I can't recognize it. Thank you in advance.

create table elba7430.kurinys(
    id INTEGER not null check (id > 10000),
    pavadinimas VARCHAR (55) not null,
    metai YEAR,
    meno_rusies_id INTEGER not null check (meno_rusies_id > 100),
    autoriaus_id INTEGER not null check (autoriaus_id > 1000000),
    kliento_id INTEGER not null check (kliento_id > 1000000),
    ilgis_cm DECIMAL (100,2),
    plotis_cm DECIMAL (100,2),
    kaina DECIMAL (100,2),
    primary key (id),
    foreign key (meno_rusies_id) 
        REFERENCES elba7430.meno_rusis on delete cascade on update restrict,
    foreign key (autoriaus_id) 
        REFERENCES elba7430.autorius on delete cascade on update restrict,
    foreign key (kliento_id)
        REFERENCES elba7430.klientas on delete cascade on update restrict
);


create table elba7430.meno_rusis(
        id INTEGER not null check (id > 100),
        pavadinimas VARCHAR (100) not null,
        primary key(id)
);

create table elba7430.autorius(
    id INTEGER not null check (id > 1000000),
    vardas VARCHAR (40) not null,
    pavarde VARCHAR (55) not null,
    gimimo_metai DATE,
    primary key(id)
);

create table elba7430.klientas(
    id INTEGER not null check (id > 1000000),
    vardas VARCHAR (40),
    pavarde VARCHAR (55),
    primary key(id)
);

CodePudding user response:

Changing the order of your declarations and replacing the year data type by a valid one will solve this issue, here you can replicate this: db<>fiddle

  • Related