0

I am new to PostgreSQL. I was trying to create a table and tried to add a primary key and auto increment in same column and came up with an ERROR

ERROR:  syntax error at or near "SERIAL"
LINE 2:  upID int SERIAL primary key

Below is my Query

create table tblIK(
    upID int SERIAL primary key,
    upName varchar(100) NOT NULL,
    upMin varchar(100) NOT NULL,
    upMax varchar(100) NOT NULL,
    upYEAR Date NOT NULL,
    upMi varchar(100)NOT NULL,
    upIK varchar(100)NOT NULL
)

2 Answers 2

1

SERIAL will create an integer column for you so you don't need to specify it.

create table tblIK(
    upID SERIAL primary key,
    upName varchar(100) NOT NULL,
    upMin varchar(100) NOT NULL,
    upMax varchar(100) NOT NULL,
    upYEAR Date NOT NULL,
    upMi varchar(100)NOT NULL,
    upIK varchar(100)NOT NULL
)
Sign up to request clarification or add additional context in comments.

Comments

0

If you are using Django to construct the tables in the DB and you want an auto incrementing primary key, Django by default will creat an ID column which is an auto incrementing integer field. Saves you some lines of code :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.