Search Postgresql Archives

Re: Switching identity column to serial

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 04.02.23 21:55, Erik Wienhold wrote:
  Why doesn't this work?
  BEGIN;
  DROP SEQUENCE t_id;

[This won't work, you need to use ALTER TABLE / DROP IDENTITY.]

  CREATE SEQUENCE new_t_id_seq AS INTEGER OWNED BY t.id;
  ALTER SEQUENCE new_t_id_seq OWNER TO new_owner;
  SELECT setval('new_t_id', (SELECT MAX(id) FROM t));
  SELECT nextval('new_t_id');
  COMMIT;
This should work but I want to preserve the existing sequence instead of
re-creating it with the same properties.  That's why I was looking for a
shortcut (also code golfing and sheer curiosity).

This is possible in principle, by implementing the inverse of the "Upgrading" recipe from <https://www.2ndquadrant.com/en/blog/postgresql-10-identity-columns/>. But if you don't want to figure that out, I think dropping and recreating the sequences as suggested here seems the best solution.






[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux