Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

postgreSQL syntax error at or near "foreign"

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)
);

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading