成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

CREATE AGGREGATE 中文man頁(yè)面

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

NAME

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

SYNOPSIS

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

DESCRIPTION 描述

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

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

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

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

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

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

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

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

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

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

PARAMETERS 參數(shù)

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

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

EXAMPLES 例子

參閱 ``User-defined Aggregates''  

COMPATIBILITY 兼容性

CREATE AGGREGATE 是 PostgreSQL 語(yǔ)言的擴(kuò)展。 在 SQL 標(biāo)準(zhǔn)里沒有 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)]

責(zé)任編輯:韓亞珊 來(lái)源: CMPP.net
相關(guān)推薦

2011-08-24 09:02:10

ALTER AGGRE中文man

2011-08-24 14:06:36

DROP AGGREG中文man

2011-08-24 10:56:32

CREATE CONV中文man

2011-08-24 11:15:24

CREATE INDE中文man

2011-08-24 13:29:20

CREATE TABL中文man

2011-08-24 13:36:25

CREATE TRIG中文man

2011-08-24 13:43:09

CREATE USER中文man

2011-08-24 13:46:39

CREATE VIEW中文man

2011-08-24 13:32:56

CREATE TABL中文man

2011-08-24 10:59:19

CREATE DATA中文man

2011-08-24 11:02:11

CREATE DOMA中文man

2011-08-24 11:05:36

CREATE FUNC中文man

2011-08-24 11:10:17

CREATE GROU中文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 13:23:10

CREATE SCHE中文man

2011-08-24 13:26:19

CREATE SEQU中文man

2011-08-24 13:39:44

CREATE TYPE中文man

2011-08-24 10:53:20

CREATE CONS中文man
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)

主站蜘蛛池模板: 综合国产第二页 | 国产一区二区三区久久久久久久久 | 日韩成人久久 | 亚洲网视频 | 男人的天堂中文字幕 | 在线视频成人 | 国产精品久久久久久238 | 国产精品久久久乱弄 | 中文字幕国产 | 久久小视频 | 精品国产欧美 | 啪一啪| 91久久国产综合久久 | 久久狠狠 | 91在线一区 | 伊人网影院 | 国产精品毛片一区二区三区 | 天天色图| 亚洲h在线观看 | 九色 在线 | 一区二区不卡高清 | 久久精品免费观看 | 久久国产一区二区 | 国产精品1 | 中文字幕av一区二区三区 | 精国产品一区二区三区四季综 | 欧美日韩高清一区 | 日韩中文字幕 | 有码一区 | 精品久久久久久国产 | 久久国产精品视频 | 欧美国产免费 | 久久久久国产精品 | 一级免费a| 日本午夜免费福利视频 | 91精品国产色综合久久不卡98 | 免费观看一级毛片 | 色天堂视频 | 国产精品av久久久久久毛片 | 波多野结衣一区二区三区在线观看 | 一区欧美 |