Pablo Job
Pablo Job

Reputation: 505

How to auto increment id when copy the column into another table using PostgreSQL?

insert into usertable (employeenumber) select empno from usertemp

And this is the error

ERROR: null value in column "id" violates not-null constraint

Upvotes: 0

Views: 847

Answers (1)

Juan Carlos Oropeza
Juan Carlos Oropeza

Reputation: 48197

Just create your table using serial, that will create the sequence and the default value

  CREATE TABLE usertable ( 
        id serial, 
        employeenumber integer
  );

Insert should be the same

insert into usertable (employeenumber) select empno from usertemp

Upvotes: 1

Related Questions