BDR Documentation | |||
---|---|---|---|
Prev | Up | Chapter 10. Global Sequences | Next |
Basic usage of global sequences is trivial: In a BDR node, when creating a sequence, append USING bdr; to your sequence creation statement:
CREATE SEQUENCE test_seq USING bdr;
Once you've created a global sequence you may use it with nextval like any other sequence.
Most PostgreSQL applications don't use CREATE SEQUENCE directly; instead, they use the SERIAL pseudo-type. To accomodate this, BDR provides the default_sequenceam parameter. When set to bdr, all sequences will be automatically created as global sequences unless explicitly overridden by a USING option. So every SERIAL or BIGSERIAL will automatically be a global sequence. e.g.:
BEGIN; SET LOCAL default_sequenceam = 'bdr'; CREATE TABLE gstest ( id serial primary key, parrot text ); COMMIT;
will create a global sequence named gstest_id_seq and set the DEFAULT of gstest.id to nextval('gstest_id_seq').