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)
mergesort
  • 5,087
  • 13
  • 38
  • 63

1 Answers1

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:

Community
  • 1
  • 1
Erwin Brandstetter
  • 605,456
  • 145
  • 1,078
  • 1,228