Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- lets play with sequences:
- create table items (id serial primary key, name varchar(10));
- insert into items(name) values ('foo');
- -- manually insert into a serial is allowed BUT it breaks the sequence!
- insert into items(id,name) values (2,'foo');
- -- now what do you expect?
- select currval(pg_get_serial_sequence('items', 'id')); -- ouch! nextval is 1!!
- -- ok, let's fix it up!
- SELECT setval(pg_get_serial_sequence('items', 'id'), (select max(id)+1 from public.items));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement