0

How can I increment this id, by 4 instead of 1 as it does by default using SQLAlchemy + Postgres? I'm using SQLAlchemy, Postgres, and Alembic.

id = Column(BigInteger, primary_key=True)

1 Answer 1

1

Get the name of the underlying SEQUENCE for your serial column and change its increment:

SELECT pg_get_serial_sequence('tbl', 'id');

Then:

ALTER SEQUENCE tbl_id_seq INCREMENT 4;  -- replace with actual name

Or with a single integrated DO statement:

DO
$$BEGIN
EXECUTE format('ALTER SEQUENCE %s INCREMENT 4'
              , pg_get_serial_sequence('tbl', 'id');
END$$;

Related:

Sign up to request clarification or add additional context in comments.

2 Comments

That's using postgres. I'd ideally like something that works with SQLAlchemy/Alembic
As a temporary solution I am manually running this and it works

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.