.\" This is -*-nroff-*- .\" XXX standard disclaimer belongs here.... .\" $Header: /usr/local/cvsroot/pgsql/src/man/create_function.l,v 1.7 1998/04/07 18:12:51 momjian Exp $ .\" .\" Japanese Version Copyright (c) 1998 Michihide Hotta .\" all rights reserved. .\" Translated Wed Jun 3 18:46:34 JST 1998 .\" by Michihide Hotta .\" .TH "CREATE FUNCTION" SQL 11/05/95 PostgreSQL PostgreSQL .\"0 .SH "NAME" .\"0 create function - define a new function .SH 名前 create function - 新しい関数を作成する .\"0 .SH "SYNOPSIS" .\"0 .nf .\"0 \fBcreate function\fP function_name .\"0 \fB(\fP[type1 {, type-n}]\fB)\fP .\"0 \fBreturns\fP type-r .\"0 \fBas\fP {'/full/path/to/objectfile' | 'sql-queries'} .\"0 \fBlanguage\fP {'c' \ 'sql' \ 'internal' \ 'plname'} .\"0 .fi .SH 書式 .nf \fBcreate function\fP 関数名 \fB(\fP[type1 {, type-n}]\fB)\fP \fBreturns\fP type-r \fBas\fP {'オブジェクトファイルへのフルパス' | 'SQL クエリー'} \fBlanguage\fP {'c' \ 'sql' \ 'internal' \ 'plname'} .fi .\"0 .SH "DESCRIPTION" .\"0 With this command, a Postgres user can register a function with .\"0 Postgres. Subsequently, this user is treated as the owner of the .\"0 function. .SH 説明 このコマンドにより、Postgres のユーザが Postgres に対して関数を 登録できる。これに伴って、このユーザはその関数の所有者となる。 .PP .\"0 When defining a function with arguments, the input data types, .\"0 .IR type-1 , .\"0 .IR type-2 , .\"0 \&..., .\"0 .IR type-n , .\"0 and the return data type, .\"0 .IR type-r .\"0 must be specified, along with the language, which may be .\"0 .IR "\*(lqc\*(rq" .\"0 or .\"0 .IR "\*(lqsql\*(rq" . .\"0 or .\"0 .IR "\*(lqinternal\*(rq" . .\"0 or .\"0 .IR "\*(lqplname\*(rq" . .\"0 (The .\"0 .IR "plname" .\"0 is the language name of a created procedural language. See .\"0 create language(l) for details.) .\"0 (The .\"0 .IR "arg is" .\"0 clause may be left out if the function has no arguments, or .\"0 alternatively the argument list may be left empty.) .\"0 The input types may be base or complex types, or .\"0 .IR opaque . .\"0 .IR Opaque .\"0 indicates that the function accepts arguments of an .\"0 invalid type such as (char *). .\"0 The output type may be specified as a base type, complex type, .\"0 .IR "setof ", .\"0 or .\"0 .IR opaque . .\"0 The .\"0 .IR setof .\"0 modifier indicates that the function will return a set of items, .\"0 rather than a single item. .\"0 The .\"0 .IR as .\"0 clause of the command is treated differently for C and SQL .\"0 functions, as explained below. 引数を持つ関数を定義する場合は、入力データ型 .IR type-1 , .IR type-2 , \&..., .IR type-n , と返り値のデータ型 .IR type-r を、 .IR "\*(lqc\*(rq" や .IR "\*(lqsql\*(rq" や .IR "\*(lqinternal\*(rq" や .IR "\*(lqplname\*(rq" という言語にしたがって指定しなければならない。( .IR "plname" は、作成された手続き型言語の言語名である。詳細については create language(l) を参照のこと)。 (関数が引数を持たない場合は .IR "arg is" 句が残ってしまうかもしれない。そうしないと、引数リストが 空になってしまう)。 入力型はベース型、複合型、または .IR opaque のいずれかである。 .IR opaque は、その関数が (char *) のような無効な型の引数であっても受け付ける ことを示す。出力型はベース型、複合型、 .IR "setof <型>" または .IR opaque のいずれかである。 .IR "setof" 修飾子は、その関数が単一項目ではなく項目のセットを返すことを示す。 コマンドの .IR as 句は、以下に示すように、C と SQL で異なって扱われることを示す。 .\"0 .SH "C FUNCTIONS" .\"0 Functions written in C can be defined to Postgres, which will .\"0 dynamically load them into its address space. The loading .\"0 happens either using .\"0 .IR load (l) .\"0 or automatically the first time the function is necessary for .\"0 execution. Repeated execution of a function will cause negligible .\"0 additional overhead, as the function will remain in a main memory .\"0 cache. .SH "C 関数" C で書かれた関数を Postgres に定義できるが、これらはアドレス空間 に対して動的にロードされる。ローディングは、 .IR load (l) を使ったり、その関数が最初に必要になった時に行われる。関数を何回 も続けて実行する場合でも、その関数がメモリキャッシュに入っている ためオーバーヘッドはほとんどかからない。 .PP .\"0 Internal functions are functions written in C which have been .\"0 statically linked into the postgres backend process. The .\"0 .BR as .\"0 clause must still be specified when defining an internal .\"0 function but the contents are ignored. 内部関数は C で書かれ、postgres のバックエンドプロセスに静的に リンクされている。内部関数を定義する場合でも、なお .BR as 句は必要である。指定しないと関数の内容が無視されてしまう。 .\"0 .SH "Writing C Functions" .\"0 The body of a C function following .\"0 .BR as .\"0 should be the .\"0 .BR "FULL PATH" .\"0 of the object code (.o file) for the function, bracketed by .\"0 quotation marks. (Postgres will not compile a function .\"0 automatically - it must be compiled before it is used in a .\"0 .BR "define function" .\"0 command.) .SH "C の関数を書く" .BR as に続く C 関数本体は、関数のオブジェクトコード (.o ファイル)への .BR フルパス を、引用符で括って指定する。(Postgres は、関数を自動的にコンパイル したりはしない。その関数は、 .BR "define function" コマンドで使われる前にコンパイルされていなければならない。) .PP .\"0 C functions with base type arguments can be written in a .\"0 straightforward fashion. The C equivalents of built-in .\"0 Postgres types are accessible in a C file if ベース型を持つ C 関数は、素直な書き方で書かれていなければならない。 C と同等の Postgres 組込み型は、 .nf \&.../src/backend/utils/builtins.h .fi .\"0 is included as a header file. This can be achieved by having がヘッダファイルとしてインクルードされていれば C ファイルで アクセス可能である。これを行うには、C のソースファイルの先頭に .nf \&#include .fi .\"0 at the top of the C source file and by compiling all C files .\"0 with the following include options: を入れておき、すべての C ファイルを以下のオプションで コンパイルする。 .PP .IR cc コマンドラインにおけるすべての \*(lq.c\*(rq プログラムの前に .nf -I.../src/backend -I.../src/backend/port/<プラットフォーム名> -I.../src/backend/obj .fi .\"0 before any \*(lq.c\*(rq programs in the .\"0 .IR cc .\"0 command line, e.g.: を指定する。たとえば、以下のようになる。 .nf cc -I.../src/backend \e -I.../src/backend/port/<プラットフォーム名> \e -I.../src/backend/obj \e -c progname.c .fi .\"0 where \*(lq...\*(rq is the path to the installed Postgres source .\"0 tree and \*(lq\*(rq is the name of the port for which .\"0 the source tree has been built. ここで、\*(lq...\*(rq はインストールされた Postgres のソースツリー へのパス、 \*(lq<プラットフォーム名>\*(rq はソースツリーがビルド されたプラットフォームの名前である。 .PP .\"0 The convention for passing arguments to and from the user's C .\"0 functions is to use pass-by-value for data types that are 32 .\"0 bits (4 bytes) or smaller, and pass-by-reference for data types .\"0 that require more than 32 bits. ユーザ C 関数との引数の受け渡しは、慣習的に、32 ビット(4 バイト) などのデータ型では「値渡し」を使い、32 ビットを超えるものを要求 するデータ型では「参照渡し」を使う。 .\"0 以下の部分はオリジナルでも表示されないので翻訳していない .if t \{ The following table gives the C type required for parameters in the C functions that will be loaded into Postgres. The \*(lqDefined In\*(rq column gives the actual header file (in the .nf \&.../src/backend .fi directory) that the equivalent C type is defined. However, if you include \*(lqutils/builtins.h\*(rq, these files will automatically be included. .SH "Equivalent C Types for Built-In Postgres Types" .PP .TS center; l l l l l l. \fBBuilt-In Type\fP \fBC Type\fP \fBDefined In\fP _ abstime AbsoluteTime utils/nabstime.h bool bool include/c.h box (BOX *) utils/geo-decls.h bytea (bytea *) include/postgres.h char char N/A char16 Char16 or (char16 *) include/postgres.h cid CID include/postgres.h int2 int2 include/postgres.h int28 (int28 *) include/postgres.h int4 int4 include/postgres.h float4 float32 or (float4 *) include/c.h or include/postgres.h float8 float64 or (float8 *) include/c.h or include/postgres.h lseg (LSEG *) include/geo-decls.h name (Name) include/postgres.h oid oid include/postgres.h oid8 (oid8 *) include/postgres.h path (PATH *) utils/geo-decls.h point (POINT *) utils/geo-decls.h regproc regproc or REGPROC include/postgres.h reltime RelativeTime utils/nabstime.h text (text *) include/postgres.h tid ItemPointer storage/itemptr.h tinterval TimeInterval utils/nabstime.h uint2 uint16 include/c.h uint4 uint32 include/c.h xid (XID *) include/postgres.h .TE \} .PP .\"0 Complex arguments to C functions are passed into the C function .\"0 as a special C type, TUPLE, defined in C 関数への複雑な引数は、 .nf \&.../src/libpq/libpq-fe.h .fi で定義される特別な C の型 タプル(TUPLE) として C 関数に渡される。 .\"0 Given a variable .\"0 .IR t .\"0 of this type, the C function may extract attributes from the .\"0 function using the function call: この型で与えられた変数 .IR t を、C 関数は以下の関数コールにより抽出することができる。 .nf .\"0 GetAttributeByName(t, "fieldname", &isnull) GetAttributeByName(t, "フィールド名", &isnull) .fi .\"0 where .\"0 .IR isnull .\"0 is a pointer to a .\"0 .IR bool , .\"0 which the function sets to .\"0 .IR true .\"0 if the field is null. The result of this function should be .\"0 cast appropriately as shown in the examples below. ここで .IR isnull は、そのフィールドが NULL の場合関数が .\"0 .IR 真 にセットする .\"0 .IR bool 型へのポインタである。この関数の結果は、以下の例で示すように 適切にキャストされる場合もある。 .\"0 .SH "Compiling Dynamically-Loaded C Functions" .SH "動的にロードされる C 関数をコンパイルする" .PP .\"0 Different operating systems require different procedures for .\"0 compiling C source files so that Postgres can load them .\"0 dynamically. This section discusses the required compiler .\"0 and loader options on each system. 異なったオペレーティングシステムでは C のソースファイルを コンパイルするのに異なった手続きを要求するので、Postgres はそれらを動的にロードできる。この章では、各システムにおいて 必要なコンパイラとローダのオプションを解説する。 .PP .\"0 Under Linux ELF, object files can be generated by specifing the .\"0 compiler flag -fpic. Linux ELF においては、コンパイラフラグとして -fpic を指定する ことによりオブジェクトファイルを生成することができる。 .PP .\"0 Under Ultrix, all object files that Postgres is expected to load .\"0 dynamically must be compiled using .\"0 .IR /bin/cc .\"0 with the \*(lq-G 0\*(rq option turned on. The object file name .\"0 in the .\"0 .IR as .\"0 clause should end in \*(lq.o\*(rq. Ultrix では、Postgres が動的にロードすることを期待している すべてのオブジェクトファイルは、 .IR /bin/cc を使い、\*(lq-G 0\*(rq オプションを有効にしてコンパイルされて いなければならない。また、 .IR as 句で指定されるオブジェクトファイルは \*(lq.o\*(rq で終わって いる必要がある。 .PP .\"0 Under HP-UX, DEC OSF/1, AIX and SunOS 4, all object files must be .\"0 turned into .\"0 .IR "shared libraries" .\"0 using the operating system's native object file loader, .\"0 .IR ld (1). HP-UX, DEC OSF/1, AIX および SunOS 4 においては、すべての オブジェクトファイルは、オペレーティングシステムネイティブの オブジェクトファイル・ローダである .IR ld (1) を使って .IR "共有ライブラリ" になっていなければならない。 .PP .\"0 Under HP-UX, an object file must be compiled using the native .\"0 HP-UX C compiler, .\"0 .IR /bin/cc , .\"0 with both the \*(lq+z\*(rq and \*(lq+u\*(rq flags turned on. .\"0 The first flag turns the object file into .\"0 \*(lqposition-independent code\*(rq (PIC); the second flag .\"0 removes some alignment restrictions that the PA-RISC .\"0 architecture normally enforces. The object file must then .\"0 be turned into a shared library using the HP-UX loader, .\"0 .IR /bin/ld . .\"0 The command lines to compile a C source file, \*(lqfoo.c\*(rq, .\"0 look like: .\"0 .nf .\"0 cc +z +u -c foo.c .\"0 ld -b -o foo.sl foo.o .\"0 .fi .\"0 The object file name in the .\"0 .BR as .\"0 clause should end in \*(lq.sl\*(rq. HP-UX では、オブジェクトファイルはネイティブの HP-UX C コンパイラである .IR /bin/cc を使い、フラグ \*(lq+z\*(rq と \*(lq+u\*(rq を両方有効にして コンパイルされている必要がある。最初のフラグは、オブジェクト ファイルを \*(lq位置独立コード\*(rq (PIC) にし、2 番目の フラグは PA-RISC アーキテクチャにおいて通常行われるアライン メント制限を取り除くものである。その後、オブジェクトファイル は HP-UX ローダ .IR /bin/ld を使って共有ライブラリに変換される。C ソースファイル \*(lqfoo.c\*(rq をコンパイルする際のコマンドラインは 以下のようになる。 .nf cc <その他のフラグ> +z +u -c foo.c ld <その他のフラグ> -b -o foo.sl foo.o .fi .BR as 句におけるオブジェクトファイル名は \*(lq.sl\*(rq で終わって いなければならない。 .PP .\"0 An extra step is required under versions of HP-UX prior to 9.00. .\"0 If the Postgres header file .\"0 .nf .\"0 include/c.h .\"0 .fi .\"0 is not included in the source file, then the following line .\"0 must also be added at the top of every source file: .\"0 .nf .\"0 #pragma HP_ALIGN HPUX_NATURAL_S500 .\"0 .fi .\"0 However, this line must not appear in programs compiled under .\"0 HP-UX 9.00 or later. HP-UX の 9.00 より前のバージョンでは、さらに余分なステップ が必要となる。もしソースファイル中に Postgres のヘッダファイル .nf include/c.h .fi が含まれていないと、さらに以下の行を各ソースファイルの先頭に 追加しなければならない。 .nf #pragma HP_ALIGN HPUX_NATURAL_S500 .fi しかしながらこの行は、HP-UX の 9.00 以降でコンパイルする場合は あってはならない。 .PP .\"0 Under DEC OSF/1, an object file must be compiled and then turned .\"0 into a shared library using the OSF/1 loader, .\"0 .IR /bin/ld . .\"0 In this case, the command lines look like: .\"0 .nf .\"0 cc -c foo.c .\"0 ld -shared -expect_unresolved '*' -o foo.so foo.o .\"0 .fi .\"0 The object file name in the .\"0 .BR as .\"0 clause should end in \*(lq.so\*(rq. DEC OSF/1 では、オブジェクトファイルはコンパイルされた後 OSF/1 のローダ .IR /bin/ld を使って共有ライブラリに変換しなければならない。 この場合、コマンドラインは以下のようになる。 .nf cc <その他のフラグ> -c foo.c ld <その他のフラグ> -shared -expect_unresolved '*' -o foo.so foo.o .fi .BR as 句におけるオブジェクトファイル名は \*(lq.so\*(rq で終わって いなければならない。 .PP .\"0 Under SunOS 4, an object file must be compiled and then turned .\"0 into a shared library using the SunOS 4 loader, .\"0 .IR /bin/ld . .\"0 The command lines look like: .\"0 .nf .\"0 cc -PIC -c foo.c .\"0 ld -dc -dp -Bdynamic -o foo.so foo.o .\"0 .fi .\"0 The object file name in the .\"0 .BR as .\"0 clause should end in \*(lq.so\*(rq. SunOS 4 では、オブジェクトファイルはコンパイルされた後 SunOS 4 のローダ .IR /bin/ld を使って共有ライブラリに変換しなければならない。 この場合、コマンドラインは以下のようになる。 .nf cc <その他のフラグ> -PIC -c foo.c ld <その他のフラグ> -dc -dp -Bdynamic -o foo.so foo.o .fi .BR as 句におけるオブジェクトファイル名は \*(lq.so\*(rq で終わって いなければならない。 .PP .\"0 Under AIX, object files are compiled normally but building the .\"0 shared library requires a couple of steps. First, create the .\"0 object file: .\"0 .nf .\"0 cc -c foo.c .\"0 .fi .\"0 You must then create a symbol \*(lqexports\*(rq file for the .\"0 object file: .\"0 .nf .\"0 mkldexport foo.o `pwd` > foo.exp .\"0 .fi .\"0 Finally, you can create the shared library: .\"0 .nf .\"0 ld -H512 -T512 -o foo.so -e _nostart \e .\"0 -bI:.../lib/postgres.exp -bE:foo.exp foo.o \e .\"0 -lm -lc 2>/dev/null .\"0 .fi .\"0 You should look at the Postgres User's Manual for an explanation .\"0 of this procedure. AIX では、オブジェクトファイルは普通にコンパイルしてよいが、 共有ライブラリを作るのにいくつかのステップが必要である。まず、 オブジェクトファイルを作る。 .nf cc <その他のフラグ> -c foo.c .fi 次に、オブジェクトファイルのためのシンボルを \*(lqエクスポート\*(rq するファイルを作らなければならない。 .nf mkldexport foo.o `pwd` > foo.exp .fi 最後に共有ライブラリを作る。 .nf ld -H512 -T512 -o foo.so -e _nostart \e -bI:.../lib/postgres.exp -bE:foo.exp foo.o \e -lm -lc 2>/dev/null .fi Postgres User's Manual で、この手続きに関する説明を 読んでおいた方がよいだろう。 .\"0 .SH "SQL FUNCTIONS" .\"0 SQL functions execute an arbitrary list of SQL queries, .\"0 returning the results of the last query in the list. .\"0 SQL functions in general return sets. If their returntype .\"0 is not specified as a .\"0 .IR setof , .\"0 then an arbitrary element of the last query's result will be .\"0 returned. .SH "SQL 関数" SQL 関数は SQL 問い合わせの調停リストを実行し、リストの中の最後の 問い合わせに対する結果を返す。一般的に、SQL 関数はセットを返す。 戻り値の型が .IR setof として指定されていないと、最後の問い合わせの結果のうちの、 要素の何れかが返されてしまう。 .PP .\"0 The body of a SQL function following .\"0 .BR as .\"0 should be a list of queries separated by whitespace characters .\"0 and bracketed within quotation marks. Note that quotation .\"0 marks used in the queries must be escaped, by preceding them .\"0 with two backslashes .\"0 (i.e. \e'). SQL 関数の本体は、ホワイトスペースで区切られ、引用符でくくられた 問い合わせのリストでなければならない。問い合わせ中に引用符を使う 場合は、2 つのバックスラッシュを前に置いてエスケープされていなけ ればならない(すなわち \e')。 .PP .\"0 Arguments to the SQL function may be referenced in the queries .\"0 using a $n syntax: $1 refers to the first argument, $2 to the .\"0 second, and so on. If an argument is complex, then a .\"0 \*(lqdot\*(rq notation may be used to access attributes of the .\"0 argument (e.g. \*(lq$1.emp\*(rq), or to invoke functions via a .\"0 nested-dot syntax. SQL 関数への引数は、問い合わせの中で $n 書式を使って参照される。 $1 は最初の引数、$2 は 2 番目の引数というように。引数が複雑な 場合は引数の属性(たとえば \*(lq$1.emp\*(rq) にアクセスするのに \*(lqドット\*(rq 記法が使われたり、ネストしたドットの書式を 通して関数が呼び出される。 .\"0 .SH "PL FUNCTIONS" .\"0 Procedural languages aren't builtin to Postgres. They are .\"0 offered by loadable modules. Please refer to the documentation .\"0 for the PL in question for details about the syntax and how the .\"0 .IR "as" .\"0 clause is interpreted by the PL handler. .SH "PL 関数" 手続き型言語は Postgres には組み込まれておらず、ローダブル・ モジュールとして提供される。PL のための書式に関する詳細や、 PL ハンドラがどのように .IR "as" 句を解釈するかに関しては、関連の文書を参照してほしい。 .\"0 .SH "EXAMPLES: C Functions" .\"0 The following command defines a C function, overpaid, of two .\"0 basetype arguments. .SH "例:C の関数" 以下のコマンドは、引数として 2 つのベース型を持つ C の関数 overpaid を定義する。 .nf create function overpaid (float8, int4) returns bool as '/usr/postgres/src/adt/overpaid.o' language 'c' .fi .\"0 The C file "overpaid.c" might look something like: C のファイル "overpaid.c" は以下のようになるだろう。 .nf #include bool overpaid(salary, age) float8 *salary; int4 age; { if (*salary > 200000.00) return(TRUE); if ((age < 30) & (*salary > 100000.00)) return(TRUE); return(FALSE); } .fi .\"0 The overpaid function can be used in a query, e.g: 関数 overpaid は、問い合わせの中で以下のような使い方をされる。 .nf select name from 従業員 where overpaid(給与, 年齢) .fi .\"0 One can also write this as a function of a single .\"0 argument of type EMP: また別の人が、従業員型の 1 つの引数を取る以下のような関数を 書くこともできる。 .nf create function overpaid_2 (EMP) returns bool as '/usr/postgres/src/adt/overpaid_2.o' language 'c' .fi .\"0 The following query is now accepted: これで以下のような問い合わせが可能となる。 .nf select name from 従業員 where overpaid_2(EMP) .fi .\"0 In this case, in the body of the overpaid_2 function, the .\"0 fields in the EMP record must be extracted. The C file .\"0 "overpaid_2.c" might look something like: このケースでは、overpaid_2 関数の中で従業員レコードを取り 出さなければならない。C のファイル "overpaid_2.c" は以下の ようになるだろう。 .nf #include #include bool overpaid_2(t) TUPLE t; { float8 *salary; int4 age; bool salnull, agenull; salary = (float8 *)GetAttributeByName(t, "salary", &salnull); age = (int4)GetAttributeByName(t, "age", &agenull); if (!salnull && *salary > 200000.00) return(TRUE); if (!agenull && (age<30) && (*salary > 100000.00)) return(TRUE); return(FALSE) } .fi .\"0 .SH "EXAMPLES: SQL Functions" .\"0 To illustrate a simple SQL function, consider the following, .\"0 which might be used to debit a bank account: .SH "例:SQL 関数" ある単純な SQL 関数について説明をするために、以下のことを 考えてみる。これは銀行口座で預金の引き出しが発生した時に 使えるかもしれない。 .nf create function TP1 (int4, float8) returns int4 as 'update 銀行口座 set 残高 = 銀行口座.残高 - $2 where 銀行口座.口座番号 = $1 select(x = 1)' language 'sql' .fi .\"0 A user could execute this function to debit account 17 by .\"0 $100.00 as follows: あるユーザは、17 番口座から $100.00 引き出す時に、この関数を 以下のように実行するだろう。 .nf select (x = TP1( 17,100.0)) .fi .\"0 The following more interesting examples take a single .\"0 argument of type EMP, and retrieve multiple results: 以下にもっとおもしろい例を挙げてみる。ここでは従業員型の 1 つの引数を与えて複数の結果を取り出す。 .nf select function hobbies (従業員) returns set of 趣味 as 'select (趣味.all) from 趣味 where $1.名前 = 趣味.人名' language 'sql' .\"0 .SH "SEE ALSO" .SH 関連事項 .PP information(1), load(l), drop function(l), create language(l). .\"0 .SH "NOTES" .SH 注意 .\"0 .SH "Name Space Conflicts" .SH "名前空間の競合" .\"0 More than one function may be defined with the same name, .\"0 as long as the arguments they take are different. In other .\"0 words, function names can be .\"0 .IR overloaded . 引数が異なっているような 1 つ以上の関数が、同じ名前で定義 されているかもしれない。言い換えると、関数名は .IR オーバーロード されうる。 .\"0 A function may also have the same name as an attribute. In .\"0 the case that there is an ambiguity between a function on a .\"0 complex type and an attribute of the complex type, the .\"0 attribute will always be used. 関数はまた、属性として同じ名前を持つこともできる。複雑な型の 関数と複雑な型の属性との間に曖昧さがある場合、常に属性が 使われる。 .\"0 .SH "RESTRICTIONS" .\"0 The name of the C function must be a legal C function name, .\"0 and the name of the function in C code must be exactly the .\"0 same as the name used in .\"0 .BR "create function" . .\"0 There is a subtle implication of this restriction: while the .\"0 dynamic loading routines in most operating systems are more .\"0 than happy to allow you to load any number of shared libraries .\"0 that contain conflicting (identically-named) function names, .\"0 they may in fact botch the load in interesting ways. For .\"0 example, if you define a dynamically-loaded function that .\"0 happens to have the same name as a function built into .\"0 Postgres, the DEC OSF/1 dynamic loader causes Postgres to .\"0 call the function within itself rather than allowing Postgres .\"0 to call your function. Hence, if you want your function to .\"0 be used on different architectures, we recommend that you .\"0 do not overload C function names. .SH 制限事項 C の関数名は正式な C 関数名でなくてはならず、また C のコード 内部の関数名は .BR "create function" で指定された関数名と完全に一致していなければならない。 この制限事項に関する困った実装系がある。ほとんどのオペレーテ ィングシステムにおける動的ローディングのルーチンでは、(一意の 名前を持つ)関数名が衝突するような、任意の数の共有ライブラリを ローディングすることができてしまうため、事実上とんでもない ところでローディングに失敗してしまうことがありうる。たとえば、 Postgres に組み込まれている関数と同じ名前を持つ、動的にローデ ィングされる関数が定義された場合、DEC OSF/1 の動的ローダは Postgres にその関数を呼ばせず、組み込み関数の方が呼ばれてしま ったりする。そのため、異なったアーキテクチャ上で自前の関数を 呼びたい場合は、C の関数名をオーバーロードしない方がよいだろう。 .PP .\"0 There is a clever trick to get around the problem just .\"0 described. Since there is no problem overloading SQL .\"0 functions, you can define a set of C functions with .\"0 different names and then define a set of identically-named .\"0 SQL function wrappers that take the appropriate argument .\"0 types and call the matching C function. この問題を回避するための巧妙なトリックがある。SQL 関数をオー バーロードするのは問題ないので、C 関数のセットを違った名前で 定義しておき、さらに、適切な引数の型を受け取って対応する C 関数 を呼ぶような、SQL 関数のラッパーを SQL 関数と同じ名前で定義する のである。 .PP .\"0 .IR opaque .\"0 cannot be given as an argument to a SQL function. .IR opaque は SQL 関数に引数として渡すことはできない。 .\"0 .SH "BUGS" .\"0 C functions cannot return a set of values. .SH バグ C 関数は値のセットを返すことはできない。 .SH 翻訳者 堀田 倫英