One Sequence for all tables or one Sequence for each table?

From: Janning Vygen <vygen(at)gmx(dot)de>
To: pgsql-general(at)postgresql(dot)org
Subject: One Sequence for all tables or one Sequence for each table?
Date: 2005-06-02 08:36:20
Message-ID: 200506021036.20460.vygen@gmx.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

if you define a SERIAL column postgresql's default is to generate a sequence
for each SERIAL column (table_column_seq). But you can use one sequence for
the whole database like this:

CREATE dbsequence;
CREATE TABLE one (
id int4 NOT NULL DEFAULT nextval('dbseq')
);
CREATE TABLE two (
id int4 NOT NULL DEFAULT nextval('dbseq')
);

One drawback: You reach the internal end of a sequence faster if you use your
sequence for all tables. But this can be avoided if you use int8 datatype.

Are there other drawbacks/benfits using one Sequence for each table or one
sequence for all tables?

kind regards,
janning

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Himanshu Baweja 2005-06-02 09:03:37 Stats not getting updated....
Previous Message ouyang_jw 2005-06-02 08:18:05 Re: writting a large store procedure