Search code examples
sqlpostgresqlcreate-table

I am creating a table in pgweb Heroku, and get this error "ERROR: pq: syntax error at or near "(""


Here is my exact query

CREATE Table Publisher 
(Publisher_Id     Int primary key not null,
Name          varchar(20) not null,  
Address       varchar(50) not null,
Phone         Int(10),
Isbn          varchar(13) references books (Isbn) not null
)

Any help would be greatly appreciated.


Solution

  • datatype int does not take a length. So:

    create table publisher (
        publisher_id  int primary key,
        name          varchar(20) not null,  
        address       varchar(50) not null,
        phone         int,
        isbn          varchar(13) references books (isbn) not null
    );
    

    Notes:

    • not null is redondant on a primary key column

    • int does not seem like a good pick for a phone number; you would typically need to store leading 0s, or allow special characters such as + or () - int cannot do that. A string datatype would probably be a better pick