In postgres sql, at the time of insert data from select to another table , I have to build a sequence depending upon the session, for every session sequence should have start from 1 and increment by one. when new session inserted sequence should start from 1.
CodePudding user response:
Calculate sequence on insert:
insert into mytable (session, sequence, ...)
values (1, (select count(*) 1 from mytable where session = 1), ...)
See live demo.