自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

CREATE AGGREGATE 中文man頁面

系統(tǒng)
CREATE AGGREGATE 定義一個新的聚集函數(shù)。 一些用于基本類型的聚集函數(shù)如 min(integer) 和 avg(double precision) 等已經(jīng)包含在基礎軟件包里了。 如果你需要定義一個新類型或需要一個還沒有提供的聚集函數(shù),這時便可用 CREATE AGGREGATE 來提供我們所需要的特性。

NAME

CREATE AGGREGATE - 定義一個新的聚集函數(shù)

SYNOPSIS

CREATE AGGREGATE name (
    BASETYPE = input_data_type,
    SFUNC = sfunc,
    STYPE = state_data_type
    [ , FINALFUNC = ffunc ]
    [ , INITCOND = initial_condition ]
)

DESCRIPTION 描述

CREATE AGGREGATE 定義一個新的聚集函數(shù)。 一些用于基本類型的聚集函數(shù)如 min(integer) 和 avg(double precision) 等已經(jīng)包含在基礎軟件包里了。 如果你需要定義一個新類型或需要一個還沒有提供的聚集函數(shù),這時便可用 CREATE AGGREGATE 來提供我們所需要的特性。

如果給出了一個模式的名字(比如,CREATE AGGREGATE myschema.myagg ...),那么該聚集函數(shù)是在指定模式中創(chuàng)建的。 否則它是在當前模式中創(chuàng)建的。

一個聚集函數(shù)是用它的名字和輸入數(shù)據(jù)類型來標識的。 同一模式中如果兩個聚集處理的輸入數(shù)據(jù)不同,它們可以有相同的名字。 一個聚集函數(shù)的輸入數(shù)據(jù)類型必須和所有同一模式中的普通函數(shù)的名字和輸入類型不同。

一個聚集函數(shù)是用一個或兩個普通函數(shù)做成的: 一個狀態(tài)轉(zhuǎn)換函數(shù) sfunc, 和一個可選的終計算函數(shù) ffunc. 它們是這樣使用的:

sfunc( internal-state, next-data-item ) ---> next-internal-state
ffunc( internal-state ) ---> aggregate-value

PostgreSQL 創(chuàng)建一個類型為 stype的臨時變量。 它保存這個聚集的當前內(nèi)部狀態(tài)。 對于每個輸入數(shù)據(jù)條目, 都調(diào)用狀態(tài)轉(zhuǎn)換函數(shù)計算內(nèi)部狀態(tài)值的新數(shù)值。 在處理完所有數(shù)據(jù)后,調(diào)用一次最終處理函數(shù)以計算聚集的返回值。 如果沒有最終處理函數(shù),那么將最后的狀態(tài)值當做返回值。

一個聚集函數(shù)還可能提供一個初始條件,也就是說,所用的該內(nèi)部狀態(tài)值的初始值。 這個值是作為一個類型為 text 的字段存儲在數(shù)據(jù)庫里的, 不過它們必須是狀態(tài)值數(shù)據(jù)類型的合法的外部表現(xiàn)形式的常量。 如果沒有提供狀態(tài),那么狀態(tài)值初始化為 NULL。

如果該狀態(tài)轉(zhuǎn)換函數(shù)被定義為 "strict", 那么就不能用 NULL 輸入調(diào)用它。這個時候,帶有這樣的轉(zhuǎn)換函數(shù)的聚集執(zhí)行起來的現(xiàn)象如下所述。 NULL 輸入的值被忽略(不調(diào)用此函數(shù)并且保留前一個狀態(tài)值)。如果初始狀態(tài)值是 NULL,那么由第一個非 NULL 值替換該狀態(tài)值, 而狀態(tài)轉(zhuǎn)換函數(shù)從第二個非 NULL 的輸入值開始調(diào)用。這樣做讓我們比較容易實現(xiàn)象 max 這樣的聚集。 請注意這種行為只是當 state_type 與 input_data_type 相同的時候才表現(xiàn)出來。 如果這些類型不同,你必須提供一個非 NULL 的初始條件或者使用一個非strice的狀態(tài)轉(zhuǎn)換函數(shù)。

如果狀態(tài)轉(zhuǎn)換函數(shù)不是 strict(嚴格)的, 那么它將無條件地為每個輸入值調(diào)用, 并且必須自行處理 NULL 輸入和 NULL 轉(zhuǎn)換值, 這樣就允許聚集的作者對聚集中的空值有完全的控制。

如果終轉(zhuǎn)換函數(shù)定義為"strict",則如果最終狀態(tài)值是 NULL 時就不會調(diào)用它; 而是自動輸出一個NULL的結(jié)果。(當然,這才是 strict 函數(shù)的正常特征。) 不管是那種情況,終處理函數(shù)可以選擇返回 NULL。比如, avg 的終處理函數(shù)在零輸入記錄時就會返回 NULL。  

PARAMETERS 參數(shù)

name
要創(chuàng)建的聚集函數(shù)名(可以有模式修飾的)。
input_data_type
本聚集函數(shù)要處理的基本數(shù)據(jù)類型。 對于不檢查輸入類型的聚集來說,這個參數(shù)可以聲明為"ANY"。 (比如 count(*))。
sfunc
用于處理源數(shù)據(jù)列里的每一個輸入數(shù)據(jù)的狀態(tài)轉(zhuǎn)換函數(shù)名稱。 它通常是一個雙參數(shù)的函數(shù),第一個參數(shù)的類型是 state_data_type 而第二個參數(shù)的類型是 input_data_type. 另外,對于一個不檢查輸入數(shù)據(jù)的聚集,該函數(shù)只接受一個類型為 state_data_type 的參數(shù)。 不管是哪種情況,此函數(shù)必須返回一個類型為 state_data_type的值。 這個函數(shù)接受當前狀態(tài)值和當前輸入數(shù)據(jù)條目,而返回下個狀態(tài)值。
state_data_type
聚集的狀態(tài)值的數(shù)據(jù)類型。
ffunc
在轉(zhuǎn)換完所有輸入域/字段后調(diào)用的最終處理函數(shù)。它計算聚集的結(jié)果。 此函數(shù)必須接受一個類型為 state_data_type 的參數(shù)。 聚集的輸出數(shù)據(jù)類型被定義為此函數(shù)的返回類型。 如果沒有聲明 ffunc 則使用聚集結(jié)果的狀態(tài)值作為聚集的結(jié)果,而輸出類型為 state_data_type。
initial_condition
狀態(tài)值的初始設置(值)。它必須是一個數(shù)據(jù)類型 state_data_type 可以接受的文本常量值。 如果沒有聲明,狀態(tài)值初始為 NULL。

CREATE AGGREGATE 的參數(shù)可以以任何順序書寫,而不只是上面顯示的順序。

EXAMPLES 例子

參閱 ``User-defined Aggregates''  

COMPATIBILITY 兼容性

CREATE AGGREGATE 是 PostgreSQL 語言的擴展。 在 SQL 標準里沒有 CREATE AGGREGATE。  

SEE ALSO 參見

ALTER AGGREGATE [alter_aggregate(7)], DROP AGGREGATE [drop_aggregate(l)]  

#p#

NAME

CREATE AGGREGATE - define a new aggregate function

SYNOPSIS

CREATE AGGREGATE name (
    BASETYPE = input_data_type,
    SFUNC = sfunc,
    STYPE = state_data_type
    [ , FINALFUNC = ffunc ]
    [ , INITCOND = initial_condition ]
)

DESCRIPTION

CREATE AGGREGATE defines a new aggregate function. Some aggregate functions for base types such as min(integer) and avg(double precision) are already provided in the standard distribution. If one defines new types or needs an aggregate function not already provided, then CREATE AGGREGATE can be used to provide the desired features.

If a schema name is given (for example, CREATE AGGREGATE myschema.myagg ...) then the aggregate function is created in the specified schema. Otherwise it is created in the current schema.

An aggregate function is identified by its name and input data type. Two aggregates in the same schema can have the same name if they operate on different input types. The name and input data type of an aggregate must also be distinct from the name and input data type(s) of every ordinary function in the same schema.

An aggregate function is made from one or two ordinary functions: a state transition function sfunc, and an optional final calculation function ffunc. These are used as follows:

sfunc( internal-state, next-data-item ) ---> next-internal-state
ffunc( internal-state ) ---> aggregate-value

PostgreSQL creates a temporary variable of data type stype to hold the current internal state of the aggregate. At each input data item, the state transition function is invoked to calculate a new internal state value. After all the data has been processed, the final function is invoked once to calculate the aggregate's return value. If there is no final function then the ending state value is returned as-is.

An aggregate function may provide an initial condition, that is, an initial value for the internal state value. This is specified and stored in the database as a column of type text, but it must be a valid external representation of a constant of the state value data type. If it is not supplied then the state value starts out null.

If the state transition function is declared ``strict'', then it cannot be called with null inputs. With such a transition function, aggregate execution behaves as follows. Null input values are ignored (the function is not called and the previous state value is retained). If the initial state value is null, then the first nonnull input value replaces the state value, and the transition function is invoked beginning with the second nonnull input value. This is handy for implementing aggregates like max. Note that this behavior is only available when state_data_type is the same as input_data_type. When these types are different, you must supply a nonnull initial condition or use a nonstrict transition function.

If the state transition function is not strict, then it will be called unconditionally at each input value, and must deal with null inputs and null transition values for itself. This allows the aggregate author to have full control over the aggregate's handling of null values.

If the final function is declared ``strict'', then it will not be called when the ending state value is null; instead a null result will be returned automatically. (Of course this is just the normal behavior of strict functions.) In any case the final function has the option of returning a null value. For example, the final function for avg returns null when it sees there were zero input rows.  

PARAMETERS

name
The name (optionally schema-qualified) of the aggregate function to create.
input_data_type
The input data type on which this aggregate function operates. This can be specified as "ANY" for an aggregate that does not examine its input values (an example is count(*)).
sfunc
The name of the state transition function to be called for each input data value. This is normally a function of two arguments, the first being of type state_data_type and the second of type input_data_type. Alternatively, for an aggregate that does not examine its input values, the function takes just one argument of type state_data_type. In either case the function must return a value of type state_data_type. This function takes the current state value and the current input data item, and returns the next state value.
state_data_type
The data type for the aggregate's state value.
ffunc
The name of the final function called to compute the aggregate's result after all input data has been traversed. The function must take a single argument of type state_data_type. The return data type of the aggregate is defined as the return type of this function. If ffunc is not specified, then the ending state value is used as the aggregate's result, and the return type is state_data_type.
initial_condition
The initial setting for the state value. This must be a string constant in the form accepted for the data type state_data_type. If not specified, the state value starts out null.

The parameters of CREATE AGGREGATE can be written in any order, not just the order illustrated above.

EXAMPLES

See the section called ``User-defined Aggregates'' in the documentation.  

COMPATIBILITY

CREATE AGGREGATE is a PostgreSQL language extension. The SQL standard does not provide for user-defined aggregate function.  

SEE ALSO

ALTER AGGREGATE [alter_aggregate(7)], DROP AGGREGATE [drop_aggregate(l)]

責任編輯:韓亞珊 來源: CMPP.net
相關推薦

2011-08-24 14:06:36

DROP AGGREG中文man

2011-08-24 09:02:10

ALTER AGGRE中文man

2011-08-24 13:43:09

CREATE USER中文man

2011-08-24 13:46:39

CREATE VIEW中文man

2011-08-24 13:29:20

CREATE TABL中文man

2011-08-24 13:36:25

CREATE TRIG中文man

2011-08-24 10:56:32

CREATE CONV中文man

2011-08-24 11:15:24

CREATE INDE中文man

2011-08-24 13:32:56

CREATE TABL中文man

2011-08-24 13:23:10

CREATE SCHE中文man

2011-08-24 10:59:19

CREATE DATA中文man

2011-08-24 11:02:11

CREATE DOMA中文man

2011-08-24 13:26:19

CREATE SEQU中文man

2011-08-24 11:18:53

CREATE LANG中文man

2011-08-24 11:23:20

CREATE OPER中文man

2011-08-24 11:31:47

CREATE RULE中文man

2011-08-24 11:05:36

CREATE FUNC中文man

2011-08-24 13:39:44

CREATE TYPE中文man

2011-08-24 11:10:17

CREATE GROU中文man

2011-08-25 14:07:55

create_modu中文man
點贊
收藏

51CTO技術棧公眾號