提交 43dd7315 编写于 作者: C Chuck Litzell 提交者: David Yozie

docs: add Enum datatype (#1782)

* docs: add Enum datatype

* docs: add a release note for enum datatype

* remove optimizer support statement.
上级 a574b248
......@@ -236,6 +236,7 @@
<topicref href="ref_guide/system_catalogs/pg_database.xml"/>
<topicref href="ref_guide/system_catalogs/pg_depend.xml"/>
<topicref href="ref_guide/system_catalogs/pg_description.xml"/>
<topicref href="ref_guide/system_catalogs/pg_enum.xml"/>
<topicref href="ref_guide/system_catalogs/pg_exttable.xml"/>
<topicref href="ref_guide/system_catalogs/pg_filespace.xml"/>
<topicref href="ref_guide/system_catalogs/pg_filespace_entry.xml"/>
......
......@@ -235,6 +235,18 @@ SELECT foo();
>age<p>current_date</p><p>current_time</p><p>current_timestamp</p><p>localtime</p><p>localtimestamp</p><p>now</p></entry>
<entry colname="col4"/>
</row>
<row>
<entry colname="col1">
<xref format="html"
href="https://www.postgresql.org/docs/8.3/static/functions-enum.html"
scope="external">
Enum Support Functions
</xref>
</entry>
<entry colname="col2"/>
<entry colname="col3"/>
<entry colname="col4"/>
</row>
<row>
<entry colname="col1">
<xref format="html"
......
......@@ -169,6 +169,7 @@
<topicref href="system_catalogs/pg_database.xml"/>
<topicref href="system_catalogs/pg_depend.xml"/>
<topicref href="system_catalogs/pg_description.xml"/>
<topicref href="system_catalogs/pg_enum.xml"/>
<topicref href="system_catalogs/pg_exttable.xml"/>
<topicref href="system_catalogs/pg_filespace.xml"/>
<topicref href="system_catalogs/pg_filespace_entry.xml"/>
......
......@@ -3,6 +3,8 @@
PUBLIC "-//OASIS//DTD DITA Composite//EN" "ditabase.dtd">
<topic id="topic1"><title id="ch20941">CREATE TYPE</title><body><p id="sql_command_desc">Defines a new data type.</p><section id="section2"><title>Synopsis</title><codeblock id="sql_command_synopsis">CREATE TYPE <varname>name</varname> AS ( <varname>attribute_name</varname> <varname>data_type</varname> [, ... ] )
CREATE TYPE <varname>name</varname> AS ENUM ( '<varname>label</varname>' [, ... ] )
CREATE TYPE <varname>name</varname> (
INPUT = <varname>input_function</varname>,
OUTPUT = <varname>output_function</varname>
......@@ -26,7 +28,14 @@ The composite type is specified by a list of attribute names and data
types. This is essentially the same as the row type of a table, but using
<codeph>CREATE TYPE</codeph> avoids the need to create an actual table
when all that is wanted is to define a type. A stand-alone composite
type is useful as the argument or return type of a function.</p></sectiondiv><sectiondiv id="section5"><b>Base Types</b><p>The second form of <codeph>CREATE TYPE</codeph>
type is useful as the argument or return type of a function.</p></sectiondiv>
<sectiondiv id="enum"><b>Enumerated Types</b>
<p>The second form of <codeph>CREATE TYPE</codeph> creates an enumerated (<codeph>ENUM</codeph>) type, as described in
<xref href="https://www.postgresql.org/docs/8.3/static/datatype-enum.html" format="html" scope="external">Enumerated Types</xref> in the
PostgreSQL documentation. Enum types take a list of one or more quoted labels, each of which must be less than
<codeph>NAMEDATALEN</codeph> bytes long (64 in a standard build).</p>
</sectiondiv>
<sectiondiv id="section5"><b>Base Types</b><p>The third form of <codeph>CREATE TYPE</codeph>
creates a new base type (scalar type). The parameters may appear in any order,
not only that shown in the syntax, and most are optional. You must register two
or more functions (using <codeph>CREATE FUNCTION</codeph>) before defining the
......@@ -150,7 +159,12 @@ generalized internal representation used by <codeph>array_in</codeph>
and <codeph>array_out</codeph>. For historical reasons, subscripting
of fixed-length array types starts from zero, rather than from one as
for variable-length arrays.</p></sectiondiv></section><section id="section7"><title>Parameters</title><parml><plentry><pt><varname>name</varname></pt><pd>The name (optionally schema-qualified) of a type to be created. </pd></plentry><plentry><pt><varname>attribute_name</varname></pt><pd>The name of an attribute (column) for the composite type. </pd></plentry><plentry><pt><varname>data_type</varname></pt><pd>The name of an existing data type to become a column of the composite
type. </pd></plentry><plentry><pt><varname>input_function</varname></pt><pd>The name of a function that converts data from the type's external
type. </pd></plentry>
<plentry>
<pt><varname>label</varname></pt>
<pd>A string literal representing the textual label associated with one value of an enum type.</pd>
</plentry>
<plentry><pt><varname>input_function</varname></pt><pd>The name of a function that converts data from the type's external
textual form to its internal form. </pd></plentry><plentry><pt><varname>output_function</varname></pt><pd>The name of a function that converts data from the type's internal
form to its external textual form. </pd></plentry><plentry><pt><varname>receive_function</varname></pt><pd>The name of a function that converts data from the type's external
binary form to its internal form. </pd></plentry><plentry><pt><varname>send_function</varname></pt><pd>The name of a function that converts data from the type's internal
......@@ -188,7 +202,21 @@ in C.</p></section><section id="section9"><title>Examples</title><p>This example
CREATE FUNCTION getfoo() RETURNS SETOF compfoo AS $$
SELECT fooid, fooname FROM foo
$$ LANGUAGE SQL;</codeblock><p>This example creates the base data type <codeph>box</codeph> and then uses the type in a table
$$ LANGUAGE SQL;</codeblock>
<p>This example creates the enumerated type <codeph>mood</codeph> and uses it in a table definition.</p>
<codeblock>CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy');
CREATE TABLE person (
name text,
current_mood mood
);
INSERT INTO person VALUES ('Moe', 'happy');
SELECT * FROM person WHERE current_mood = 'happy';
name | current_mood
------+--------------
Moe | happy
(1 row)
</codeblock>
<p>This example creates the base data type <codeph>box</codeph> and then uses the type in a table
definition:</p><codeblock>CREATE TYPE box;
CREATE FUNCTION my_box_in_function(cstring) RETURNS box AS
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE topic
PUBLIC "-//OASIS//DTD DITA Composite//EN" "ditabase.dtd">
<topic id="topic1" xml:lang="en">
<title id="fv141670">pg_enum</title>
<body>
<p>The <codeph>pg_enum</codeph> table contains entries matching enum types to their associated
values and labels. The internal representation of a given enum value is actually the OID of
its associated row in <codeph>pg_enum</codeph>. The OIDs for a particular enum type are
guaranteed to be ordered in the way the type should sort, but there is no guarantee about the
ordering of OIDs of unrelated enum types.</p>
<table id="fv141982">
<title>pg_catalog.pg_enum</title>
<tgroup cols="4">
<colspec colnum="1" colname="col1" colwidth="131pt"/>
<colspec colnum="2" colname="col2" colwidth="86pt"/>
<colspec colnum="3" colname="col3" colwidth="85pt"/>
<colspec colnum="4" colname="col4" colwidth="147pt"/>
<thead>
<row>
<entry colname="col1">Column</entry>
<entry colname="col2">Type</entry>
<entry colname="col3">References</entry>
<entry colname="col4">Description</entry>
</row>
</thead>
<tbody>
<row>
<entry colname="col1"><codeph>enumtypid</codeph></entry>
<entry colname="col2">oid</entry>
<entry colname="col3">pgtype.oid</entry>
<entry>The OID of the <codeph>pg_type</codeph> entry owning this enum value</entry>
</row>
<row>
<entry><codeph>enumlabel</codeph></entry>
<entry>name</entry>
<entry/>
<entry>The textual label for this enum value</entry>
</row>
</tbody>
</tgroup>
</table>
</body>
</topic>
......@@ -81,8 +81,8 @@
<entry colname="col2">char</entry>
<entry colname="col3"/>
<entry colname="col4"><codeph>b</codeph> for a base type, <codeph>c</codeph> for a
composite type, <codeph>d</codeph> for a domain, or <codeph>p</codeph> for a
pseudo-type.</entry>
composite type, <codeph>d</codeph> for a domain, <codeph>e</codeph> for an enum
type, or <codeph>p</codeph> for a pseudo-type.</entry>
</row>
<row>
<entry colname="col1">
......
......@@ -44,7 +44,8 @@
<body>
<p>Greenplum Database 5.0.0 includes these new features:</p>
<ul>
<li>Add new features here.</li>
<li>Enumerated data types (ENUM), introduced in PostgreSQL release 8.3.
</li>
</ul>
</body>
</topic>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册