SELECT setval(pg_get_serial_sequence(‘tags’, ‘id’), SELECT max(id) FROM tags);
Asked
Active
Viewed 40 times
0
Rahul
- 73,987
- 13
- 62
- 116
codigomonstruo
- 1,001
- 1
- 10
- 39
-
1Does this help? http://stackoverflow.com/a/3698777/1073631 – sgeddes Aug 13 '16 at 01:28
-
Using PostgreSQL inside rails. I am trying to correct it to execute inActiveRecords. I am not an expert in SQL. How would you correct it please ? – codigomonstruo Aug 13 '16 at 01:29
-
Moussa, @sgeddes, have already provided the answer to you by linking the other similar post. Go through it and change your query accordingly – Rahul Aug 13 '16 at 01:35
-
Yes, I realize that. Thanks a lot guys !!! – codigomonstruo Aug 13 '16 at 01:38
-
Possible duplicate of [How to reset postgres' primary key sequence when it falls out of sync?](http://stackoverflow.com/questions/244243/how-to-reset-postgres-primary-key-sequence-when-it-falls-out-of-sync) – Will Aug 13 '16 at 02:21
2 Answers
2
You are using curly quotes ‘’ while you should be using straight quotes '':
SELECT setval(pg_get_serial_sequence('tags', 'id'), SELECT max(id) FROM tags);
Patrick
- 26,336
- 6
- 57
- 84
1
I think this is the code you intend:
SELECT setval(pg_get_serial_sequence('tags', 'id'), maxid)
FROM ( SELECT max(id) as maxid FROM tags) t;
Gordon Linoff
- 1,198,228
- 53
- 572
- 709