Search code examples
sqlpostgresqlsyntax-errorddlcreate-table

I cannot create a table on PostgreSQL


I was trying to create the following table on PostgreSQL:

CREATE TABLE movies
(
    movie_name VARCHAR(200),
    movie_year INTEGER,         
    country VARCHAR(100),
    genre VARCHAR
    PRIMARY KEY (movie_name, movie_year) 
);

But received the following error message:

ERROR:  error de sintaxis en o cerca de «(»
LINE 7:  PRIMARY KEY 
                 ^
SQL state: 42601
Character: 166

Sorry, my PostgreSQL is in Spanish for some reason, but it basically says that there is a syntax error near the '('.

I´m following a course and the teacher was able to create this table on PostgreSQL without any problems, what am I doing wrong?


Solution

  • You're missing a comma after the last column definition:

    CREATE TABLE movies
    (
        movie_name VARCHAR(200),
        movie_year INTEGER,         
        country VARCHAR(100),
        genre VARCHAR,
        -- Here -----^
        PRIMARY KEY (movie_name, movie_year) 
    );