diff options
author | Robert Haas <rhaas@postgresql.org> | 2011-06-21 22:52:52 -0400 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2011-06-21 22:52:52 -0400 |
commit | 61307dccc5f2f352d7dfed5c13abf3f0e26ec85d (patch) | |
tree | 51fa9fb073eeb8ef9f905bd6d014232a2d881561 | |
parent | 7095003cbef630fe29c2299cc819fd37c691d0b0 (diff) | |
download | postgresql-61307dccc5f2f352d7dfed5c13abf3f0e26ec85d.tar.gz postgresql-61307dccc5f2f352d7dfed5c13abf3f0e26ec85d.zip |
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
-rw-r--r-- | doc/src/sgml/datatype.sgml | 29 | ||||
-rw-r--r-- | doc/src/sgml/ecpg.sgml | 5 | ||||
-rw-r--r-- | doc/src/sgml/func.sgml | 2 | ||||
-rw-r--r-- | 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 ab8eb2d30bb..0b4f978d985 100644 --- a/doc/src/sgml/datatype.sgml +++ b/doc/src/sgml/datatype.sgml @@ -199,6 +199,12 @@ </row> <row> + <entry><type>smallserial</type></entry> + <entry><type>serial2</type></entry> + <entry>autoincrementing two-byte integer</entry> + </row> + + <row> <entry><type>serial</type></entry> <entry><type>serial4</type></entry> <entry>autoincrementing four-byte integer</entry> @@ -369,6 +375,13 @@ </row> <row> + <entry><type>smallserial</type></entry> + <entry>2 bytes</entry> + <entry>small autoincrementing integer</entry> + <entry>1 to 32767</entry> + </row> + + <row> <entry><type>serial</></entry> <entry>4 bytes</entry> <entry>autoincrementing integer</entry> @@ -743,6 +756,10 @@ NUMERIC <title>Serial Types</title> <indexterm zone="datatype-serial"> + <primary>smallserial</primary> + </indexterm> + + <indexterm zone="datatype-serial"> <primary>serial</primary> </indexterm> @@ -751,6 +768,10 @@ NUMERIC </indexterm> <indexterm zone="datatype-serial"> + <primary>serial2</primary> + </indexterm> + + <indexterm zone="datatype-serial"> <primary>serial4</primary> </indexterm> @@ -769,8 +790,8 @@ NUMERIC </indexterm> <para> - The data types <type>serial</type> and <type>bigserial</type> - are not true types, but merely + The data types <type>smallserial</type>, <type>serial</type> and + <type>bigserial</type> are not true types, but merely a notational convenience for creating unique identifier columns (similar to the <literal>AUTO_INCREMENT</literal> property supported by some other databases). In the current @@ -828,7 +849,9 @@ ALTER SEQUENCE <replaceable class="parameter">tablename</replaceable>_<replaceab the same way, except that they create a <type>bigint</type> column. <type>bigserial</type> should be used if you anticipate the use of more than 2<superscript>31</> identifiers over the - lifetime of the table. + lifetime of the table. The type names <type>smallserial</type> and + <type>serial2</type> also work the same way, execpt that they + create a <type>smallint</type> column. </para> <para> 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 @@ -845,6 +845,11 @@ do </row> <row> + <entry><type>smallserial</type></entry> + <entry><type>short</type></entry> + </row> + + <row> <entry><type>serial</type></entry> <entry><type>int</type></entry> </row> 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); <row> <entry><literal><function>pg_get_serial_sequence(<parameter>table_name</parameter>, <parameter>column_name</parameter>)</function></literal></entry> <entry><type>text</type></entry> - <entry>get name of the sequence that a <type>serial</type> or <type>bigserial</type> column + <entry>get name of the sequence that a <type>serial</type>, <type>smallserial</type> or <type>bigserial</type> column uses</entry> </row> <row> 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; |