Add smallserial pseudotype.
authorRobert Haas <rhaas@postgresql.org>
Wed, 22 Jun 2011 02:52:52 +0000 (22:52 -0400)
committerRobert Haas <rhaas@postgresql.org>
Wed, 22 Jun 2011 02:52:52 +0000 (22:52 -0400)
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
doc/src/sgml/ecpg.sgml
doc/src/sgml/func.sgml
src/backend/parser/parse_utilcmd.c

index ab8eb2d30bb8c3c72036c14f4752ea12f724fa1b..0b4f978d985ba2c5d7fdf2fab9ab523aefedb4a7 100644 (file)
        <entry>signed two-byte integer</entry>
       </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>15 decimal digits precision</entry>
        </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>
@@ -742,6 +755,10 @@ NUMERIC
    <sect2 id="datatype-serial">
     <title>Serial Types</title>
 
+    <indexterm zone="datatype-serial">
+     <primary>smallserial</primary>
+    </indexterm>
+
     <indexterm zone="datatype-serial">
      <primary>serial</primary>
     </indexterm>
@@ -750,6 +767,10 @@ NUMERIC
      <primary>bigserial</primary>
     </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>
index def250c156c88df52e2e1917c178b6f649ba7599..847012293beac796196f8fb699d88bbbb89bf679 100644 (file)
@@ -844,6 +844,11 @@ do
        <entry><type>double</type></entry>
       </row>
 
+      <row>
+       <entry><type>smallserial</type></entry>
+       <entry><type>short</type></entry>
+      </row>
+
       <row>
        <entry><type>serial</type></entry>
        <entry><type>int</type></entry>
index 8f223d68913747c8446aa38928a9589079cf776f..628fbef001799df2c0a68a161db589e0f5d58b40 100644 (file)
@@ -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>
index 622efe592d406e375f894d1ba0cd3b2633e4cb2c..8744654f34a0db4e46efba277badc07e2ed7c42d 100644 (file)
@@ -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;