From: Robert Haas Date: Wed, 22 Jun 2011 02:52:52 +0000 (-0400) Subject: Add smallserial pseudotype. X-Git-Tag: REL9_2_BETA1~1519 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=61307dccc5f2f352d7dfed5c13abf3f0e26ec85d;p=thirdparty%2Fpostgresql.git Add smallserial pseudotype. This is just like serial and bigserial, except it generates an int2 column rather than int4 or int8. Mike Pultz, reviewed by Brar Piening and Josh Kupershmidt --- diff --git a/doc/src/sgml/datatype.sgml b/doc/src/sgml/datatype.sgml index ab8eb2d30bb..0b4f978d985 100644 --- a/doc/src/sgml/datatype.sgml +++ b/doc/src/sgml/datatype.sgml @@ -198,6 +198,12 @@ signed two-byte integer + + smallserial + serial2 + autoincrementing two-byte integer + + serial serial4 @@ -368,6 +374,13 @@ 15 decimal digits precision + + smallserial + 2 bytes + small autoincrementing integer + 1 to 32767 + + serial 4 bytes @@ -742,6 +755,10 @@ NUMERIC Serial Types + + smallserial + + serial @@ -750,6 +767,10 @@ NUMERIC bigserial + + serial2 + + serial4 @@ -769,8 +790,8 @@ NUMERIC - The data types serial and bigserial - are not true types, but merely + The data types smallserial, serial and + bigserial are not true types, but merely a notational convenience for creating unique identifier columns (similar to the AUTO_INCREMENT property supported by some other databases). In the current @@ -828,7 +849,9 @@ ALTER SEQUENCE tablename_bigint column. bigserial should be used if you anticipate the use of more than 231 identifiers over the - lifetime of the table. + lifetime of the table. The type names smallserial and + serial2 also work the same way, execpt that they + create a smallint column. diff --git a/doc/src/sgml/ecpg.sgml b/doc/src/sgml/ecpg.sgml index def250c156c..847012293be 100644 --- a/doc/src/sgml/ecpg.sgml +++ b/doc/src/sgml/ecpg.sgml @@ -844,6 +844,11 @@ do double + + smallserial + short + + serial int diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index 8f223d68913..628fbef0017 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -13366,7 +13366,7 @@ SELECT pg_type_is_visible('myschema.widget'::regtype); pg_get_serial_sequence(table_name, column_name) text - get name of the sequence that a serial or bigserial column + get name of the sequence that a serial, smallserial or bigserial column uses diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c index 622efe592d4..8744654f34a 100644 --- a/src/backend/parser/parse_utilcmd.c +++ b/src/backend/parser/parse_utilcmd.c @@ -307,7 +307,14 @@ transformColumnDefinition(CreateStmtContext *cxt, ColumnDef *column) { char *typname = strVal(linitial(column->typeName->names)); - if (strcmp(typname, "serial") == 0 || + if (strcmp(typname, "smallserial") == 0 || + strcmp(typname, "serial2") == 0) + { + is_serial = true; + column->typeName->names = NIL; + column->typeName->typeOid = INT2OID; + } + else if (strcmp(typname, "serial") == 0 || strcmp(typname, "serial4") == 0) { is_serial = true;