Download PostgreSQL User`s Guide - BITS

Transcript
Chapter 3. Data Types
The Serial Type
The serial type is a special-case type constructed by Postgres from other existing components.
It is typically used to create unique identifiers for table entries. In the current implementation,
specifying
CREATE TABLE tablename (colname SERIAL);
is equivalent to specifying:
CREATE SEQUENCE tablename_colname_seq;
CREATE TABLE tablename
(colname INT4 DEFAULT nextval(’tablename_colname_seq’);
CREATE UNIQUE INDEX tablename_colname_key on tablename (colname);
Caution
The implicit sequence created for the serial type will not be automatically removed
when the table is dropped.
Implicit sequences supporting the serial are not automatically dropped when a table containing
a serial type is dropped. So, the following commands executed in order will likely fail:
CREATE TABLE tablename (colname SERIAL);
DROP TABLE tablename;
CREATE TABLE tablename (colname SERIAL);
The sequence will remain in the database until explicitly dropped using DROP SEQUENCE.
Monetary Type
Obsolete Type: The money is now deprecated. Use numeric or decimal instead. The
money type may become a locale-aware layer over the numeric type in a future release.
The money type supports US-style currency with fixed decimal point representation. If
Postgres is compiled with USE_LOCALE then the money type should use the monetary
conventions defined for locale(7).
26