Commit 3f936aac authored by Tom Lane's avatar Tom Lane

Add a "LIKE = typename" clause to CREATE TYPE for base types. This allows

the basic representational details (typlen, typalign, typbyval, typstorage)
to be copied from an existing type rather than listed explicitly in the
CREATE TYPE command.  The immediate reason for this is to provide a simple
solution for add-on modules that want to define types represented as int8,
float4, or float8: as of 8.4 the appropriate PASSEDBYVALUE setting is
platform-specific and so it's hard for a SQL script to know what to do.

This patch fixes the contrib/isn breakage reported by Rushabh Lathia.
parent 0ddede58
/* $PostgreSQL: pgsql/contrib/isn/isn.sql.in,v 1.8 2007/11/13 04:24:28 momjian Exp $ */ /* $PostgreSQL: pgsql/contrib/isn/isn.sql.in,v 1.9 2008/11/30 19:01:29 tgl Exp $ */
-- Adjust this setting to control where the objects get created. -- Adjust this setting to control where the objects get created.
SET search_path = public; SET search_path = public;
...@@ -28,9 +28,7 @@ CREATE OR REPLACE FUNCTION ean13_out(ean13) ...@@ -28,9 +28,7 @@ CREATE OR REPLACE FUNCTION ean13_out(ean13)
CREATE TYPE ean13 ( CREATE TYPE ean13 (
INPUT = ean13_in, INPUT = ean13_in,
OUTPUT = ean13_out, OUTPUT = ean13_out,
INTERNALLENGTH = 8, LIKE = pg_catalog.int8
ALIGNMENT = double,
STORAGE = PLAIN
); );
COMMENT ON TYPE ean13 COMMENT ON TYPE ean13
IS 'International European Article Number (EAN13)'; IS 'International European Article Number (EAN13)';
...@@ -48,9 +46,7 @@ CREATE OR REPLACE FUNCTION ean13_out(isbn13) ...@@ -48,9 +46,7 @@ CREATE OR REPLACE FUNCTION ean13_out(isbn13)
CREATE TYPE isbn13 ( CREATE TYPE isbn13 (
INPUT = isbn13_in, INPUT = isbn13_in,
OUTPUT = ean13_out, OUTPUT = ean13_out,
INTERNALLENGTH = 8, LIKE = pg_catalog.int8
ALIGNMENT = double,
STORAGE = PLAIN
); );
COMMENT ON TYPE isbn13 COMMENT ON TYPE isbn13
IS 'International Standard Book Number 13 (ISBN13)'; IS 'International Standard Book Number 13 (ISBN13)';
...@@ -68,9 +64,7 @@ CREATE OR REPLACE FUNCTION ean13_out(ismn13) ...@@ -68,9 +64,7 @@ CREATE OR REPLACE FUNCTION ean13_out(ismn13)
CREATE TYPE ismn13 ( CREATE TYPE ismn13 (
INPUT = ismn13_in, INPUT = ismn13_in,
OUTPUT = ean13_out, OUTPUT = ean13_out,
INTERNALLENGTH = 8, LIKE = pg_catalog.int8
ALIGNMENT = double,
STORAGE = PLAIN
); );
COMMENT ON TYPE ismn13 COMMENT ON TYPE ismn13
IS 'International Standard Music Number 13 (ISMN13)'; IS 'International Standard Music Number 13 (ISMN13)';
...@@ -88,9 +82,7 @@ CREATE OR REPLACE FUNCTION ean13_out(issn13) ...@@ -88,9 +82,7 @@ CREATE OR REPLACE FUNCTION ean13_out(issn13)
CREATE TYPE issn13 ( CREATE TYPE issn13 (
INPUT = issn13_in, INPUT = issn13_in,
OUTPUT = ean13_out, OUTPUT = ean13_out,
INTERNALLENGTH = 8, LIKE = pg_catalog.int8
ALIGNMENT = double,
STORAGE = PLAIN
); );
COMMENT ON TYPE issn13 COMMENT ON TYPE issn13
IS 'International Standard Serial Number 13 (ISSN13)'; IS 'International Standard Serial Number 13 (ISSN13)';
...@@ -110,9 +102,7 @@ CREATE OR REPLACE FUNCTION isn_out(isbn) ...@@ -110,9 +102,7 @@ CREATE OR REPLACE FUNCTION isn_out(isbn)
CREATE TYPE isbn ( CREATE TYPE isbn (
INPUT = isbn_in, INPUT = isbn_in,
OUTPUT = isn_out, OUTPUT = isn_out,
INTERNALLENGTH = 8, LIKE = pg_catalog.int8
ALIGNMENT = double,
STORAGE = PLAIN
); );
COMMENT ON TYPE isbn COMMENT ON TYPE isbn
IS 'International Standard Book Number (ISBN)'; IS 'International Standard Book Number (ISBN)';
...@@ -130,9 +120,7 @@ CREATE OR REPLACE FUNCTION isn_out(ismn) ...@@ -130,9 +120,7 @@ CREATE OR REPLACE FUNCTION isn_out(ismn)
CREATE TYPE ismn ( CREATE TYPE ismn (
INPUT = ismn_in, INPUT = ismn_in,
OUTPUT = isn_out, OUTPUT = isn_out,
INTERNALLENGTH = 8, LIKE = pg_catalog.int8
ALIGNMENT = double,
STORAGE = PLAIN
); );
COMMENT ON TYPE ismn COMMENT ON TYPE ismn
IS 'International Standard Music Number (ISMN)'; IS 'International Standard Music Number (ISMN)';
...@@ -150,9 +138,7 @@ CREATE OR REPLACE FUNCTION isn_out(issn) ...@@ -150,9 +138,7 @@ CREATE OR REPLACE FUNCTION isn_out(issn)
CREATE TYPE issn ( CREATE TYPE issn (
INPUT = issn_in, INPUT = issn_in,
OUTPUT = isn_out, OUTPUT = isn_out,
INTERNALLENGTH = 8, LIKE = pg_catalog.int8
ALIGNMENT = double,
STORAGE = PLAIN
); );
COMMENT ON TYPE issn COMMENT ON TYPE issn
IS 'International Standard Serial Number (ISSN)'; IS 'International Standard Serial Number (ISSN)';
...@@ -170,9 +156,7 @@ CREATE OR REPLACE FUNCTION isn_out(upc) ...@@ -170,9 +156,7 @@ CREATE OR REPLACE FUNCTION isn_out(upc)
CREATE TYPE upc ( CREATE TYPE upc (
INPUT = upc_in, INPUT = upc_in,
OUTPUT = isn_out, OUTPUT = isn_out,
INTERNALLENGTH = 8, LIKE = pg_catalog.int8
ALIGNMENT = double,
STORAGE = PLAIN
); );
COMMENT ON TYPE upc COMMENT ON TYPE upc
IS 'Universal Product Code (UPC)'; IS 'Universal Product Code (UPC)';
......
<!-- <!--
$PostgreSQL: pgsql/doc/src/sgml/ref/create_type.sgml,v 1.78 2008/11/14 10:22:46 petere Exp $ $PostgreSQL: pgsql/doc/src/sgml/ref/create_type.sgml,v 1.79 2008/11/30 19:01:29 tgl Exp $
PostgreSQL documentation PostgreSQL documentation
--> -->
...@@ -39,6 +39,7 @@ CREATE TYPE <replaceable class="parameter">name</replaceable> ( ...@@ -39,6 +39,7 @@ CREATE TYPE <replaceable class="parameter">name</replaceable> (
[ , PASSEDBYVALUE ] [ , PASSEDBYVALUE ]
[ , ALIGNMENT = <replaceable class="parameter">alignment</replaceable> ] [ , ALIGNMENT = <replaceable class="parameter">alignment</replaceable> ]
[ , STORAGE = <replaceable class="parameter">storage</replaceable> ] [ , STORAGE = <replaceable class="parameter">storage</replaceable> ]
[ , LIKE = <replaceable class="parameter">like_type</replaceable> ]
[ , CATEGORY = <replaceable class="parameter">category</replaceable> ] [ , CATEGORY = <replaceable class="parameter">category</replaceable> ]
[ , PREFERRED = <replaceable class="parameter">preferred</replaceable> ] [ , PREFERRED = <replaceable class="parameter">preferred</replaceable> ]
[ , DEFAULT = <replaceable class="parameter">default</replaceable> ] [ , DEFAULT = <replaceable class="parameter">default</replaceable> ]
...@@ -290,6 +291,21 @@ CREATE TYPE <replaceable class="parameter">name</replaceable> ...@@ -290,6 +291,21 @@ CREATE TYPE <replaceable class="parameter">name</replaceable>
<literal>external</literal> items.) <literal>external</literal> items.)
</para> </para>
<para>
The <replaceable class="parameter">like_type</replaceable> parameter
provides an alternative method for specifying the basic representation
properties of a data type: copy them from some existing type. The values of
<replaceable class="parameter">internallength</replaceable>,
<replaceable class="parameter">passedbyvalue</replaceable>,
<replaceable class="parameter">alignment</replaceable>, and
<replaceable class="parameter">storage</replaceable> are copied from the
named type. (It is possible, though usually undesirable, to override
some of these values by specifying them along with the <literal>LIKE</>
clause.) Specifying representation this way is especially useful when
the low-level implementation of the new type <quote>piggybacks</> on an
existing type in some fashion.
</para>
<para> <para>
The <replaceable class="parameter">category</replaceable> and The <replaceable class="parameter">category</replaceable> and
<replaceable class="parameter">preferred</replaceable> parameters can be <replaceable class="parameter">preferred</replaceable> parameters can be
...@@ -524,6 +540,22 @@ CREATE TYPE <replaceable class="parameter">name</replaceable> ...@@ -524,6 +540,22 @@ CREATE TYPE <replaceable class="parameter">name</replaceable>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><replaceable class="parameter">like_type</replaceable></term>
<listitem>
<para>
The name of an existing data type that the new type will have the
same representation as. The values of
<replaceable class="parameter">internallength</replaceable>,
<replaceable class="parameter">passedbyvalue</replaceable>,
<replaceable class="parameter">alignment</replaceable>, and
<replaceable class="parameter">storage</replaceable>
are copied from that type, unless overridden by explicit
specification elsewhere in this <command>CREATE TYPE</> command.
</para>
</listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term><replaceable class="parameter">category</replaceable></term> <term><replaceable class="parameter">category</replaceable></term>
<listitem> <listitem>
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment