.\" This is -*-nroff-*- .\" XXX standard disclaimer belongs here.... .\" $Header: /usr/local/cvsroot/pgsql/src/man/create_aggregate.l,v 1.5 1998/01/11 22:17:11 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 AGGREGATE" SQL 11/05/95 PostgreSQL PostgreSQL .\"0 .SH NAME .\"0 create aggregate - define a new aggregate .SH 名前 create aggregate - 新しい集約関数を定義する .\"0 .SH SYNOPSIS .\"0 .nf .\"0 \fBcreate aggregate\fR agg-name [\fBas\fR] .\"0 \fB(\fP[\fBsfunc1\fR \fB=\fR state-transition-function-1 .\"0 ,\fP \fBbasetype\fR \fB=\fR data-type .\"0 ,\fP \fBstype1\fR \fB=\fR sfunc1-return-type] .\"0 [\fB,\fP \fBsfunc2\fR \fB=\fR state-transition-function-2 .\"0 ,\fP \fBstype2\fR \fB=\fR sfunc2-return-type] .\"0 [\fB,\fP \fBfinalfunc\fR \fB=\fR final-function] .\"0 [\fB,\fP \fBinitcond1\fR \fB=\fR initial-condition-1] .\"0 [\fB,\fP \fBinitcond2\fR \fB=\fR initial-condition-2]\fB)\fR .\"0 .fi .SH 書式 .nf \fBcreate aggregate\fR 集合名 [\fBas\fR] \fB(\fP[\fBsfunc1\fR \fB=\fR 状態遷移関数1 ,\fP \fBbasetype\fR \fB=\fR データ型 ,\fP \fBstype1\fR \fB=\fR 状態遷移関数1の返り値の型] [\fB,\fP \fBsfunc2\fR \fB=\fR 状態遷移関数2 ,\fP \fBstype2\fR \fB=\fR 状態遷移関数2の返り値の型] [\fB,\fP \fBfinalfunc\fR \fB=\fR 最終関数] [\fB,\fP \fBinitcond1\fR \fB=\fR 初期状態1] [\fB,\fP \fBinitcond2\fR \fB=\fR 初期状態2]\fB)\fR .fi .\"0 .SH DESCRIPTION .\"0 An aggregate function can use up to three functions, two .\"0 .IR "state transition" .\"0 functions, X1 and X2: .\"0 .nf .\"0 X1( internal-state1, next-data_item ) ---> next-internal-state1 .\"0 X2( internal-state2 ) ---> next-internal-state2 .\"0 .fi .\"0 and a .\"0 .BR "final calculation" .\"0 function, F: .\"0 .nf .\"0 F(internal-state1, internal-state2) ---> aggregate-value .\"0 .fi .\"0 These functions are required to have the following properties: .SH 説明 集約関数は 3 つまでの関数が使用できる。2 つの .IR "状態遷移" 関数 X1 と X2 は、 .nf X1( 内部状態1, 次のデータ項目 ) ---> 次の内部状態1 X2( 内部状態2 ) ---> 次の内部状態2 .fi であり、 .BR "最終計算" 関数 F は、 .nf F(内部状態1, 内部状態2) ---> 集合値 .fi といった形態をしている。 これらの関数は、以下の構造をしている必要がある。 .IP .\"0 The arguments to state-transition-function-1 must be .\"0 .BR ( stype1 , basetype ) , .\"0 and its return value must be stype1. 状態遷移関数1 への引数は、 .BR ( stype1 , basetype ) であり、返り値は stype1 でなければならない。 .IP .\"0 The argument and return value of state-transition-function-2 must be .\"0 .BR stype2 . 状態遷移関数2 への引数と返り値は、 .BR stype2 でなければならない。 .IP .\"0 The arguments to the final-calculation-function must be .\"0 .BR ( stype1 , stype2 ) , .\"0 and its return value must be a POSTGRES base type (not .\"0 necessarily the same as basetype. 最終計算関数 への引数は、 .BR ( stype1 , stype2 ) であり、返り値は POSTGRES のベース型でなければならない (basetype と同じである必要はない)。 .IP .\"0 The final-calculation-function should be specified if and only if both .\"0 state-transition functions are specified. 最終計算関数は、状態遷移関数が 2 つとも指定された場合のみ 指定されなければならない。 .PP .\"0 Note that it is possible to specify aggregate functions .\"0 that have varying combinations of state and final functions. .\"0 For example, the \*(lqcount\*(rq aggregate requires .\"0 .BR sfunc2 .\"0 (an incrementing function) but not .\"0 .BR sfunc1 " or " finalfunc , .\"0 whereas the \*(lqsum\*(rq aggregate requires .\"0 .BR sfunc1 .\"0 (an addition function) but not .\"0 .BR sfunc2 " or " finalfunc .\"0 and the \*(lqaverage\*(rq aggregate requires both of the .\"0 above state functions as well as a .\"0 .BR finalfunc .\"0 (a division function) to produce its answer. In any case, .\"0 at least one state function must be defined, and any .\"0 .BR sfunc2 .\"0 must have a corresponding .\"0 .BR initcond2 . 状態の結合や最終関数が変化するような集約関数を指定することも 可能であることに注意すること。たとえば、 \*(lqcount\*(rq 集約関数は .BR sfunc2 (インクリメントしてゆくような関数)を必要とするが、 .BR sfunc1 " or " finalfunc は必ずしもそうでなくてもよい、とか、\*(lqaverage\*(rq 集約関数は上の 2つの状態関数のみならず、答えを生成するための .BR 最終関数 も必要とする、などである。いかなるケースにおいても、 少なくとも 1 つの状態関数が定義されなければならず、また .BR sfunc2 はそれに対応する .BR initcond2 を持たなければならない。 .PP .\"0 Aggregates also require two initial conditions, one for each .\"0 transition function. These are specified and stored in the database .\"0 as fields of type .\"0 .IR text . 集約関数はまた、各遷移関数に対する 2 つの初期状態を必要とする。 これらは、指定されるとデータベースに .IR text 型フィールドとして格納される。 .\"0 .SH EXAMPLE .\"0 This .\"0 .IR avg .\"0 aggregate consists of two state transition functions, a addition .\"0 function and a incrementing function. These modify the internal .\"0 state of the aggregate through a running sum and and the number .\"0 of values seen so far. It accepts a new employee salary, .\"0 increments the count, and adds the new salary to produce the next .\"0 state. The state transition functions must be passed correct .\"0 initialization values. The final calculation then divides the .\"0 sum by the count to produce the final answer. 集約関数は、加算関数とインクリメント関数という 2 つの状態遷移 関数を持つ。これらの関数は合計を計算し、出現した値の件数を カウントすることにより集合の内部状態を変更する。具体的には、 新しい従業員の給与を受け取ってカウントをインクリメントし、 新しい給与を加算して次の状態を作る。状態遷移関数には正しい 初期値が与えられなければならない。その後、最終計算により合計を 件数で割って、最終的な答えが得られる。 .nf -- .\"0 --Create an aggregate for int4 average -- int4 の平均を取る集約関数を生成する -- create aggregate avg (sfunc1 = int4add, basetype = int4, stype1 = int4, sfunc2 = int4inc, stype2 = int4, finalfunc = int4div, initcond1 = "0", initcond2 = "0") .fi .\"0 .SH "SEE ALSO" .SH 関連事項 create function(l), remove aggregate(l). .SH 翻訳者 堀田 倫英