On Thu, Mar 01, 2001 at 04:49:25PM -0300, Martin A. Marques wrote:
> Hi, I would like to know which are the properties of the SERIAL type.
> Is a column defined SERIAL a primary key?
>
> Saludos... :-)
create table foo (
id serial primary key,
data text not null check(char_length(data) > 0)
);
Note: SERIAL isn't really a "type". The data type of "id" is an integer
(oid I think??), and some hooks to use a SEQUENCE for the default value
of "id" are created (as is the SEQUENCE). If you drop the table, you
also need to drop the sequence that "SERIAL" creates.
IMHO, automatically incremented number fields used for primary keys are
both a blessing and a curse. It is almost always better to use some
other data that *means something* for a primary key. If there's no
possible candidate key, *then* maybe an autonumber key is appropriate.
--
Eric G. Miller <egm2@jps.net>