Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 61307dc

Browse files
committed
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
1 parent 7095003 commit 61307dc

File tree

4 files changed

+40
-5
lines changed

4 files changed

+40
-5
lines changed

doc/src/sgml/datatype.sgml

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,12 @@
198198
<entry>signed two-byte integer</entry>
199199
</row>
200200

201+
<row>
202+
<entry><type>smallserial</type></entry>
203+
<entry><type>serial2</type></entry>
204+
<entry>autoincrementing two-byte integer</entry>
205+
</row>
206+
201207
<row>
202208
<entry><type>serial</type></entry>
203209
<entry><type>serial4</type></entry>
@@ -368,6 +374,13 @@
368374
<entry>15 decimal digits precision</entry>
369375
</row>
370376

377+
<row>
378+
<entry><type>smallserial</type></entry>
379+
<entry>2 bytes</entry>
380+
<entry>small autoincrementing integer</entry>
381+
<entry>1 to 32767</entry>
382+
</row>
383+
371384
<row>
372385
<entry><type>serial</></entry>
373386
<entry>4 bytes</entry>
@@ -742,6 +755,10 @@ NUMERIC
742755
<sect2 id="datatype-serial">
743756
<title>Serial Types</title>
744757

758+
<indexterm zone="datatype-serial">
759+
<primary>smallserial</primary>
760+
</indexterm>
761+
745762
<indexterm zone="datatype-serial">
746763
<primary>serial</primary>
747764
</indexterm>
@@ -750,6 +767,10 @@ NUMERIC
750767
<primary>bigserial</primary>
751768
</indexterm>
752769

770+
<indexterm zone="datatype-serial">
771+
<primary>serial2</primary>
772+
</indexterm>
773+
753774
<indexterm zone="datatype-serial">
754775
<primary>serial4</primary>
755776
</indexterm>
@@ -769,8 +790,8 @@ NUMERIC
769790
</indexterm>
770791

771792
<para>
772-
The data types <type>serial</type> and <type>bigserial</type>
773-
are not true types, but merely
793+
The data types <type>smallserial</type>, <type>serial</type> and
794+
<type>bigserial</type> are not true types, but merely
774795
a notational convenience for creating unique identifier columns
775796
(similar to the <literal>AUTO_INCREMENT</literal> property
776797
supported by some other databases). In the current
@@ -828,7 +849,9 @@ ALTER SEQUENCE <replaceable class="parameter">tablename</replaceable>_<replaceab
828849
the same way, except that they create a <type>bigint</type>
829850
column. <type>bigserial</type> should be used if you anticipate
830851
the use of more than 2<superscript>31</> identifiers over the
831-
lifetime of the table.
852+
lifetime of the table. The type names <type>smallserial</type> and
853+
<type>serial2</type> also work the same way, execpt that they
854+
create a <type>smallint</type> column.
832855
</para>
833856

834857
<para>

doc/src/sgml/ecpg.sgml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,11 @@ do
844844
<entry><type>double</type></entry>
845845
</row>
846846

847+
<row>
848+
<entry><type>smallserial</type></entry>
849+
<entry><type>short</type></entry>
850+
</row>
851+
847852
<row>
848853
<entry><type>serial</type></entry>
849854
<entry><type>int</type></entry>

doc/src/sgml/func.sgml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13366,7 +13366,7 @@ SELECT pg_type_is_visible('myschema.widget'::regtype);
1336613366
<row>
1336713367
<entry><literal><function>pg_get_serial_sequence(<parameter>table_name</parameter>, <parameter>column_name</parameter>)</function></literal></entry>
1336813368
<entry><type>text</type></entry>
13369-
<entry>get name of the sequence that a <type>serial</type> or <type>bigserial</type> column
13369+
<entry>get name of the sequence that a <type>serial</type>, <type>smallserial</type> or <type>bigserial</type> column
1337013370
uses</entry>
1337113371
</row>
1337213372
<row>

src/backend/parser/parse_utilcmd.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,14 @@ transformColumnDefinition(CreateStmtContext *cxt, ColumnDef *column)
307307
{
308308
char *typname = strVal(linitial(column->typeName->names));
309309

310-
if (strcmp(typname, "serial") == 0 ||
310+
if (strcmp(typname, "smallserial") == 0 ||
311+
strcmp(typname, "serial2") == 0)
312+
{
313+
is_serial = true;
314+
column->typeName->names = NIL;
315+
column->typeName->typeOid = INT2OID;
316+
}
317+
else if (strcmp(typname, "serial") == 0 ||
311318
strcmp(typname, "serial4") == 0)
312319
{
313320
is_serial = true;

0 commit comments

Comments
 (0)