From 61307dccc5f2f352d7dfed5c13abf3f0e26ec85d Mon Sep 17 00:00:00 2001 From: Robert Haas Date: Tue, 21 Jun 2011 22:52:52 -0400 Subject: [PATCH] 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 --- doc/src/sgml/datatype.sgml | 29 ++++++++++++++++++++++++++--- doc/src/sgml/ecpg.sgml | 5 +++++ doc/src/sgml/func.sgml | 2 +- src/backend/parser/parse_utilcmd.c | 9 ++++++++- 4 files changed, 40 insertions(+), 5 deletions(-) diff --git a/doc/src/sgml/datatype.sgml b/doc/src/sgml/datatype.sgml index ab8eb2d30b..0b4f978d98 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 def250c156..847012293b 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 8f223d6891..628fbef001 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 622efe592d..8744654f34 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;