0
SELECT setval(pg_get_serial_sequence(‘tags’, ‘id’), SELECT max(id) FROM tags);
Rahul
  • 76,197
  • 13
  • 71
  • 125
codigomonstruo
  • 1,081
  • 1
  • 11
  • 45
  • 1
    Does 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 Answers2

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
  • 29,357
  • 6
  • 62
  • 90
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,242,037
  • 58
  • 646
  • 786