How to create sequence if not exists

后端 未结 6 1186
隐瞒了意图╮
隐瞒了意图╮ 2020-12-09 08:17

I tried to use code from Check if sequence exists in Postgres (plpgsql).

To create sequence if it does not exists. Running this code two times causes an exception:

6条回答
  •  佛祖请我去吃肉
    2020-12-09 08:34

    If you don't need to preserve the potentially existing sequence, you could just drop it and then recreate it:

    DROP SEQUENCE IF EXISTS id_seq;
    CREATE SEQUENCE id_seq;
    

提交回复
热议问题