CREATE TYPE

Name

CREATE TYPE  --  Defines a new base data type 新しい基本データ型を定義します。

Synopsis

CREATE TYPE typename (
        INPUT          = input_function
      , OUTPUT         = output_function
      , INTERNALLENGTH = (internallength | VARIABLE)
    [ , EXTERNALLENGTH = (externallength | VARIABLE) ]
    [ , ELEMENT        = element ]
    [ , DELIMITER      = delimiter ]
    [ , DEFAULT        = "default" ]
    [ , SEND           = send_function ]
    [ , RECEIVE        = receive_function ]
    [ , PASSEDBYVALUE ]
)
  

入力

typename

The name of a type to be created.

作成される型の名前です。

INTERNALLENGTH internallength

A literal value, which specifies the internal length of the new type.

新しい型の内部長を指定するリテラル値です。

EXTERNALLENGTH externallength

A literal value, which specifies the external length of the new type.

新しい型の外部長を指定するリテラル値です。

INPUT input_function

The name of a function, created by CREATE FUNCTION, which converts data from its external form to the type's internal form.

CREATE FUNCTION によって作成された、外部形式のデータを、 その型の内部形式のデータに変換する関数の名前です。

OUTPUT output_function

The name of a function, created by CREATE FUNCTION, which converts data from its internal form to a form suitable for display.

CREATE FUNCTION によって作成された、内部形式によるデータを 表示に適した形式のデータに変換する関数の名前です。

element

The type being created is an array; this specifies the type of the array elements.

作成されるのは配列型で、その配列の要素の型を指定します。

delimiter

The delimiter character for the array.

その配列のデリミタ文字です。

default

The default text to be displayed to indicate "data not present"

"data not present" (データがありません)という表示をする デフォルトのテキストです。

send_function

The name of a function, created by CREATE FUNCTION, which converts data of this type into a form suitable for transmission to another machine.

CREATE FUNCTION によって作成された、この型のデータを 他のマシンに転送できるような形式に変換する関数の名前です。

receive_function

The name of a function, created by CREATE FUNCTION, which converts data of this type from a form suitable for transmission from another machine to internal form.

CREATE FUNCTION によって作成された、この型のデータを 他のマシンから、内部形式に転送できるような形式に変換する 関数の名前です。

出力

CREATE

Message returned if the type is successfully created.

型が正常に作成されたときに戻るメッセージです。

説明

CREATE TYPE allows the user to register a new user data type with Postgres for use in the current data base. The user who defines a type becomes its owner. typename is the name of the new type and must be unique within the types defined for this database.

CREATE TYPE はユーザが Postgres に、 指定したデータベースで使用する新しいユーザ定義のデータ型を 登録します。 型を定義したユーザはその所有者となります。 typename は 新しい型の名前で、そのデータベースに定義された型名の中で 一意でなければなりません。

CREATE TYPE requires the registration of two functions (using create function) before defining the type. The representation of a new base type is determined by input_function, which converts the type's external representation to an internal representation usable by the operators and functions defined for the type. Naturally, output_function performs the reverse transformation. Both the input and output functions must be declared to take one or two arguments of type "opaque".

CREATE TYPE は、型を定義する前に、 (CREATE FUNCTION を用いて)二つの関数を登録する必要があります。 新しい基本型の表現は input_function で決定され、型の外部表現を、その型に対して定義された演算子と 関数が使用可能となる内部表現に変換されます。当然、 output_function は 逆変換を実行します。入力と出力の関数は共に、型 "opaque" の一つまたは二つの引数を取るように 宣言されなければなりません。

New base data types can be fixed length, in which case internallength is a positive integer, or variable length, in which case Postgres assumes that the new type has the same format as the Postgres-supplied data type, "text". To indicate that a type is variable-length, set internallength to VARIABLE. The external representation is similarly specified using the externallength keyword.

新しい基本型は、固定長の場合 internallength が 正の整数で、可変長の場合はその新しい型が Postgres が提供する データ型 "text" と同じ形式であると Postgres は推定します。 型が可変長であることを示すには、 internallengthVARIABLE に設定します。 その外部表現は、 externallength キーワードを使用して同じように指定されます。

To indicate that a type is an array and to indicate that a type has array elements, indicate the type of the array element using the element keyword. For example, to define an array of 4 byte integers ("int4"), specify

ELEMENT = int4

型が配列であり、型が配列要素を持っていることを示すには、 ELEMENT キーワードを使用して配列要素の型を指定します。 例えば、4 バイト整数 ("int4") の配列を定義するには

ELEMENT = int4
を指定 します。

To indicate the delimiter to be used on arrays of this type, delimiter can be set to a specific character. The default delimiter is the comma (",").

この型の配列に使用するデリミタを示すには、 delimiter で 特定の文字を設定します。デフォルトのデリミタはコンマ (",") です。

A default value is optionally available in case a user wants some specific bit pattern to mean "data not present." Specify the default with the DEFAULT keyword.

ユーザが "data not present" (データがありませんの表示)を意味する 特定のビットパターンを望むのであれば、デフォルト値をオプションで 指定することが出来ます。 DEFAULT キーワードでデフォルトを指定します。

The optional functions send_function and receive_function are used when the application program requesting Postgres services resides on a different machine. In this case, the machine on which Postgres runs may use a format for the data type different from that used on the remote machine. In this case it is appropriate to convert data items to a standard form when sending from the server to the client and converting from the standard format to the machine specific format when the server receives the data from the client. If these functions are not specified, then it is assumed that the internal format of the type is acceptable on all relevant machine architectures. For example, single characters do not have to be converted if passed from a Sun-4 to a DECstation, but many other types do.

アプリケーションプログラムが、Postgres サービスが別のマシン 上で動いている事を想定している場合、オプションの関数、 send_function および receive_function を使用します。この場合、Postgres が動いているマシンは、 遠隔マシンで使用されているものと異なる型形式を使用することが できます。そして、サーバからクライアントに送る時はデータ項目を 標準形式に変換し、クライアントからサーバがデータを受け取る時 は、標準形式からマシン固有の形式に変換することが適切な処理 です。これらの関数が指定されていない場合、すべてのこの件に 関連したマシンのアーキテクチャが、その型の内部形式を認識できる と推測します。例えば、他の多くの型では必要とされる、Sun-4 から DECstation に送られる一文字は変換される必要がありません。

The optional flag, PASSEDBYVALUE, indicates that operators and functions which use this data type should be passed an argument by value rather than by reference. Note that you may not pass by value types whose internal representation is more than four bytes.

オプションのフラグ、PASSEDBYVALUE は、 引数が参照によってではなく、値として渡されなければならない データ型を使用する演算子と関数であることを示します。 内部表現が 4 バイト以上の値の型を渡してはならないことに 注意して下さい。

For new base types, a user can define operators, functions and aggregates using the appropriate facilities described in this section.

新しい基本型に対し、ユーザはこの節で記述した適切な手法で 演算子、関数および集約を定義することができます。

配列型

Two generalized built-in functions, array_in and array_out, exist for quick creation of variable-length array types. These functions operate on arrays of any existing Postgres type.

二つの一般化された組み込み関数、array_in と array_out により 可変長配列型がすぐに作成可能です。これらの関数はいかなる 既存の Postgres 型による配列の上でも動きます。

ラージオブジェクト型

A "regular" Postgres type can only be 8192 bytes in length. If you need a larger type you must create a Large Object type. The interface for these types is discussed at length in The PostgreSQL Programmer's Guide. The length of all large object types is always VARIABLE.

"通常" の Postgres 型は 8192 バイトまでに限られています。 これより大きい型が必要な場合は、ラージオブジェクト型を 作成しなければなりません。これらの型に対してのインターフェイス は、PostgreSQL プログラマガイド に すべて記述されています。 ラージオブジェクト型の長さは常に VARIABLE です。

事例

This command creates the box data type and then uses the type in a class definition:

このコマンドはボックスデータ型を作成し、その型をクラス 定義の中で使用します:

CREATE TYPE box (INTERNALLENGTH = 8,
    INPUT = my_procedure_1, OUTPUT = my_procedure_2);
CREATE TABLE myboxes (id INT4, description box);
  

This command creates a variable length array type with integer elements.

このコマンドは整数要素を持つ可変長配列型を作成します:

CREATE TYPE int4array (INPUT = array_in, OUTPUT = array_out,
    INTERNALLENGTH = VARIABLE, ELEMENT = int4);
CREATE TABLE myarrays (id int4, numbers int4array);
   

This command creates a large object type and uses it in a class definition:

このコマンドはラージオブジェクト型を作成し、その型をクラス 定義の中で使用します:

CREATE TYPE bigobj (INPUT = lo_filein, OUTPUT = lo_fileout,
    INTERNALLENGTH = VARIABLE);
CREATE TABLE big_objs (id int4, obj bigobj);
   

制約条件

Type names cannot begin with the underscore character ("_") and can only be 31 characters long. This is because Postgres silently creates an array type for each base type with a name consisting of the base type's name prepended with an underscore.

型名は下線文字 ("_") で始まってはなりません。また 31 文字 以内に制限されています。ユーザには判りませんが、Postgres は 下線文字 ("_") で始まる名前のそれぞれの基本型に対する配列型 を内部的に作成するからです。

注意事項

Refer to DROP TYPE to remove an existing type.

既存の型を削除するためには DROP TYPE を 参照して下さい。

See also CREATE FUNCTION, CREATE OPERATOR and the chapter on Large Objects in the PostgreSQL Programmer's Guide.

CREATE FUNCTIONCREATE OPERATOR および PostgreSQL プログラマガイド の ラージオブジェクトに関する章も参照して下さい。

互換性

SQL3

CREATE TYPE is an SQL3 statement.

CREATE TYPESQL3 文です。