Re: Serial Vs Sequence

From: John R Pierce <pierce(at)hogranch(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Serial Vs Sequence
Date: 2011-02-01 07:08:20
Message-ID: 4D47B164.1090802@hogranch.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 01/31/11 10:55 PM, Adarsh Sharma wrote:
> Dear all,
>
> I am not able to distinct these two datatypes ( Serial and Sequence )
> in Postgresql which resembles like auto-increment in Mysql.
>
> Which one gets priority and When ?
>
> The only thing I am able to find is to use SERIAL because if a drop
> table occurs , still SEQUENCE memory is not freed, its garbage remains.
>
> However if we define a SERIAL column in a table , implicitly it makes
> a sequence.
>
> Could anyone Please describe me the difference and Which to Use When ?

neither is actually a data type.

a sequence is a special table-like object that has auto increment logic
associated with it.

a serial is a pseudotype implemented as an integer field with an
associated sequence.

when you drop a table that has an associated sequence, the sequence is
dropped automatically.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Pavel Stehule 2011-02-01 07:13:40 Re: Serial Vs Sequence
Previous Message Adarsh Sharma 2011-02-01 06:55:12 Serial Vs Sequence