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:>
I went a different route: just catch the exception:
DO $$ BEGIN CREATE SEQUENCE myseq; EXCEPTION WHEN duplicate_table THEN -- do nothing, it's already there END $$ LANGUAGE plpgsql;
One nice benefit to this is that you don't need to worry about what your current schema is.