Thread: Fwd: Sizes of sequences and serials

Fwd: Sizes of sequences and serials

From
elein
Date:
I'm sorry if this gets posted more than once. My ISP smtp servers
have gone whacky on me.

elein

----------  Forwarded Message  ----------

Subject: Sizes of sequences and serials
Date: Thu, 26 Sep 2002 16:44:45 -0700
From: elein  <elein@sbcglobal.net>
To: pgsql-general@postgresql.org
Cc: elein <elein@norcov.com>

According to the documentation, it looks like sequences
are always stored as bigints (if the platform supports them).

Serials, though, seem to be able to be declared as serial
with integer storage or serial8 for bigint storage.

Is the storage for ordinary serials really an int and not
a big int?  Is there a way to create a sequence stored
as an int instead of a big int?  For example by setting
the maximun size?

thanks,
elein@norcov.com

-------------------------------------------------------

Re: Fwd: Sizes of sequences and serials

From
Tom Lane
Date:
elein <elein@sbcglobal.net> writes:
> According to the documentation, it looks like sequences
> are always stored as bigints (if the platform supports them).

Correct.

> Serials, though, seem to be able to be declared as serial
> with integer storage or serial8 for bigint storage.

> Is the storage for ordinary serials really an int and not
> a big int?

If you declare a serial (aka serial4) column, you get an int4 column
that's driven by a bigint sequence.  No problem except for a runtime
conversion from int8 to int4, which is really pretty negligible in
comparison to the cost of nextval().

> Is there a way to create a sequence stored as an int instead of a big
> int?

No; it wouldn't save anything anyway, seeing that each sequence is
stored as a separate table and so must occupy one disk block.

            regards, tom lane