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

CREATE FUNCTION 中文man頁面

系統(tǒng)
CREATE FUNCTION 定義一個新的函數(shù)。 CREATE OR REPLACE FUNCTION 將要么創(chuàng)建一個新函數(shù), 要么替換現(xiàn)有的定義。

NAME

CREATE FUNCTION - 定義一個新函數(shù)

SYNOPSIS

CREATE [ OR REPLACE ] FUNCTION name ( [ argtype [, ...] ] )
    RETURNS rettype
  { LANGUAGE langname
    | IMMUTABLE | STABLE | VOLATILE
    | CALLED ON NULL INPUT | RETURNS NULL ON NULL INPUT | STRICT
    | [EXTERNAL] SECURITY INVOKER | [EXTERNAL] SECURITY DEFINER
    | AS 'definition'
    | AS 'obj_file', 'link_symbol'
  } ...
    [ WITH ( attribute [, ...] ) ]

DESCRIPTION 描述

CREATE FUNCTION 定義一個新的函數(shù)。 CREATE OR REPLACE FUNCTION 將要么創(chuàng)建一個新函數(shù), 要么替換現(xiàn)有的定義。


 如果包含了一個模式名,那么函數(shù)就在指定的模式中創(chuàng)建。否則它會在當前模式中創(chuàng)建。 新函數(shù)的名字不能和同一個模式中的任何帶有同樣參數(shù)類型的函數(shù)同名。 不過,參數(shù)類型不同的函數(shù)可以同名(這叫做重載)。


 要更新一個現(xiàn)有函數(shù)的定義,使用 CREATE OR REPLACE FUNCTION。 我們不能用這個方法修改一個函數(shù)的名字或者參數(shù)類型(如果你這么干,那么你就會創(chuàng)建一個新的,不同的函數(shù))。 同樣,CREATE OR REPLACE FUNCTION 也不會允許你修改一個現(xiàn)有函數(shù)的返回類型。 要做這些事情,你必須刪除并重新創(chuàng)建函數(shù)。


 如果你刪除然后重建一個函數(shù),新函數(shù)和舊的將是不同的實體;你會破壞現(xiàn)有規(guī)則,視圖,觸發(fā)器等等。 使用 CREATE OR REPLACE FUNCTION 可以在不破壞引用該函數(shù)的對象的前提下修改函數(shù)定義。


 創(chuàng)建這個函數(shù)的用戶成為函數(shù)的所有者。  

PARAMETERS 參數(shù)

name

 要創(chuàng)建的函數(shù)名字。
argtype

 該函數(shù)的數(shù)據(jù)類型(可以有模式修飾)。如果有的話,參數(shù)類型可以是基本類型,也可以是復(fù)合類型,域類型,或者和一個現(xiàn)有字段相同的類型。


 一個字段的類型是用 tablename.columnname%TYPE  表示的;使用這個東西可以幫助函數(shù)獨立于表定義的修改。


 根據(jù)實現(xiàn)語言的不同,我們還可以在這上面聲明 "偽類型", 比如 cstring。偽類型表示實際的參數(shù)類型要么是沒有完整地聲明,要么是在普通的 SQL 數(shù)據(jù)類型之外。

rettype

 返回數(shù)據(jù)類型。輸出類型可以聲明為一個基本類型,復(fù)合類型,域類型, 或者從現(xiàn)有字段拷貝。參閱上面 argtype 的描述獲取如何引用一個現(xiàn)有類型的信息。


 根據(jù)實現(xiàn)語言的不同,我們還可以在這上面聲明 "偽類型", 比如 cstring。 SETOF 修飾詞表示該函數(shù)將返回一套條目, 而不是一條條目。

langname

 用以實現(xiàn)函數(shù)的語言的名字。 可以是 SQL,C, internal,或者是用戶定義的過程語言名字。 (又見 createlang。 ) 為了保持向下兼容,該名字可以用單引號包圍。 
IMMUTABLE
STABLE
VOLATILE

 這些屬性告訴系統(tǒng)把對該函數(shù)的多次調(diào)用替換成一次是否安全。 主要用于運行時優(yōu)化。 至少應(yīng)該聲明一個選擇。如果任何一個都沒有出現(xiàn),那么 VOLATILE 是缺省假設(shè)。

IMMUTABLE 表示該函數(shù)在給出同樣的參數(shù)值時總是返回相同的結(jié)果; 也就是說,它不做數(shù)據(jù)庫查找或者是使用那些并沒有直接出現(xiàn)在其參數(shù)列表里面的信息。 如果給出這個選項,那么任何帶著全部是常量參數(shù)對該函數(shù)的調(diào)用都將立即替換為該函數(shù)的值。

STABLE 表示在一次表掃描里,對相同參數(shù)值, 該函數(shù)將穩(wěn)定返回相同的值,但是它的結(jié)果可能在不同 SQL 語句之間變化。 這個選項對那些結(jié)果倚賴數(shù)據(jù)庫查找,參數(shù)變量(比如當前時區(qū)),等等的函數(shù)是很合適的。 還要注意 current_timestamp 族函數(shù)是 stable (穩(wěn)定)的,因為它們的值在一次事務(wù)中不會變化。

VOLATILE 表示該函數(shù)值甚至可以在一次表掃描內(nèi)改變, 因此不會做任何優(yōu)化。很少數(shù)據(jù)庫函數(shù)在這個概念上是易變的; 一些例子是 random(),currval(), timeofday()。請注意任何有副作用的函數(shù)都必需列為易變類, 即使其結(jié)果相當有規(guī)律也應(yīng)該這樣,這樣才能避免它被優(yōu)化;一個例子就是 setval()。

CALLED ON NULL INPUT
RETURNS NULL ON NULL INPUT
STRICT
CALLED ON NULL INPUT (缺?。┍砻髟摵瘮?shù)在自己的某些參數(shù)是空值的時候還是可以按照正常的方式調(diào)用。 剩下的事情是函數(shù)的作者必須負責(zé)檢查空值以及相應(yīng)地做出反應(yīng)。

RETURNS NULL ON NULL INPUT 或 STRICT 表明如果它的任何參數(shù)是 NULL,此函數(shù)總是返回 NULL。 如果聲明了這個參數(shù),則如果存在 NULL 參數(shù)時不會執(zhí)行該函數(shù); 而只是自動假設(shè)一個 NULL 結(jié)果。

[EXTERNAL] SECURITY INVOKER
[EXTERNAL] SECURITY DEFINER
SECURITY INVOKER 表明該函數(shù)將帶著調(diào)用它的用戶的權(quán)限執(zhí)行。 這是缺省。SECURITY DEFINER 聲明該函數(shù)將以創(chuàng)建它的用戶的權(quán)限執(zhí)行。


 關(guān)鍵字 EXTERNAL 的目的是和 SQL 兼容, 但是我們和 SQL 不同的是,這個特性不僅僅適用于外部的函數(shù), 所以它是可選的。

definition

 一個定義函數(shù)的字串;含義取決于語言。它可以是一個內(nèi)部函數(shù)名字, 一個指向某個目標文件的路徑,一個 SQL 查詢,或者一個用過程語言寫的文本。
obj_file, link_symbol

 這個形式的 AS 子句用于在函數(shù)的 C 源文件里的函數(shù)名字和 SQL 函數(shù)的名字不同的時候可動態(tài)裝載 C 語言函數(shù)。 字串 obj_file 是包含可動態(tài)裝載的對象的文件名,而 link_symbol 是函數(shù)的鏈接符號,也就是該函數(shù)在 C 源文件里的名字。 如果省略了鏈接符號,那么就假設(shè)它和被定義的 SQL 函數(shù)同名。
attribute

 歷史遺留的函數(shù)可選信息。下面的屬性可以在此出現(xiàn):
isStrict

 等效于 STRICT 或者 RETURNS NULL ON NULL INPUT
isCachable
isCachable 是 IMMUTABLE 的過時的等效物;不過出于向下兼容,我們?nèi)匀唤邮芩?


 屬性名是大小寫無關(guān)的。  

NOTES 注意


 請參閱 ``User-Defined Functions'' 獲取更多關(guān)于書寫函數(shù)的信息。


 我們允許你將完整的 SQL 類型語法用于輸入?yún)?shù)和返回值。 不過,有些類型聲明的細節(jié)(比如,numeric 類型的精度域)是由下層函數(shù)實現(xiàn)負責(zé)的, 并且會被 CREATE FUNCTION 命令悄悄地吞掉。 (也就是說,不再被識別或強制)。

PostgreSQL 允許函數(shù)重載; 也就是說,同一個函數(shù)名可以用于幾個不同的函數(shù), 只要它們的參數(shù)可以區(qū)分它們。不過,所有函數(shù)的 C 名字必須不同, 也就是說你必須給予重載的 C 函數(shù)不同的 C 名字(比如,使用參數(shù)類型作為 C 名字的一部分)。


 如果重復(fù)調(diào)用 CREATE FUNCTION,并且都指向同一個目標文件, 那么該文件只裝載一次。要卸載和恢復(fù)裝載該文件(可能是在開發(fā)過程中),你可以使用 LOAD [load(7)] 命令。


 使用 DROP FUNCTION 刪除一個用戶定義函數(shù)。


 函數(shù)定義里面的任何單引號或者反斜杠都必須用寫雙份的方式逃逸。


 要能定義函數(shù),用戶必須對該語言有 USAGE  權(quán)限。  

EXAMPLES 例子


 這里是一個簡單的例子,用于幫助你開始掌握這個命令。 更多信息和例子,參閱 ``User-Defined Functions''。

CREATE FUNCTION add(integer, integer) RETURNS integer
    AS 'select $1 + $2;'
    LANGUAGE SQL
    IMMUTABLE
    RETURNS NULL ON NULL INPUT;

COMPATIBILITY 兼容性


 在 SQL99 里的確定義了一個CREATE FUNCTION  PostgreSQL 的和它類似但是不兼容。 這個屬性是不可移植的,可以使用的不同語言也是如此。  

SEE ALSO 參見

ALTER FUNCTION [alter_function(7)], DROP FUNCTION [drop_function(7)], GRANT [grant(7)], LOAD [load(7)], REVOKE [revoke(7)], createlang(1)  

#p#

NAME

CREATE FUNCTION - define a new function

SYNOPSIS

CREATE [ OR REPLACE ] FUNCTION name ( [ argtype [, ...] ] )
    RETURNS rettype
  { LANGUAGE langname
    | IMMUTABLE | STABLE | VOLATILE
    | CALLED ON NULL INPUT | RETURNS NULL ON NULL INPUT | STRICT
    | [EXTERNAL] SECURITY INVOKER | [EXTERNAL] SECURITY DEFINER
    | AS 'definition'
    | AS 'obj_file', 'link_symbol'
  } ...
    [ WITH ( attribute [, ...] ) ]

DESCRIPTION

CREATE FUNCTION defines a new function. CREATE OR REPLACE FUNCTION will either create a new function, or replace an existing definition.

If a schema name is included, then the function is created in the specified schema. Otherwise it is created in the current schema. The name of the new function must not match any existing function with the same argument types in the same schema. However, functions of different argument types may share a name (this is called overloading).

To update the definition of an existing function, use CREATE OR REPLACE FUNCTION. It is not possible to change the name or argument types of a function this way (if you tried, you'd just be creating a new, distinct function). Also, CREATE OR REPLACE FUNCTION will not let you change the return type of an existing function. To do that, you must drop and recreate the function.

If you drop and then recreate a function, the new function is not the same entity as the old; you will break existing rules, views, triggers, etc. that referred to the old function. Use CREATE OR REPLACE FUNCTION to change a function definition without breaking objects that refer to the function.

The user that creates the function becomes the owner of the function.  

PARAMETERS

name
The name of a function to create.
argtype
The data type(s) of the function's arguments (optionally schema-qualified), if any. The argument types may be base, complex, or domain types, or copy the type of an existing column.

The type of a column is referenced by writing tablename.columnname%TYPE; using this can sometimes help make a function independent from changes to the definition of a table.

Depending on the implementation language it may also be allowed to specify ``pseudotypes'' such as cstring. Pseudotypes indicate that the actual argument type is either incompletely specified, or outside the set of ordinary SQL data types.

rettype
The return data type (optionally schema-qualified). The return type may be specified as a base, complex, or domain type, or may copy the type of an existing column. See the description under argtype above on how to reference the type of an existing column.

Depending on the implementation language it may also be allowed to specify ``pseudotypes'' such as cstring. The SETOF modifier indicates that the function will return a set of items, rather than a single item.

langname
The name of the language that the function is implemented in. May be SQL, C, internal, or the name of a user-defined procedural language. (See also createlang [createlang(1)].) For backward compatibility, the name may be enclosed by single quotes.
IMMUTABLE
STABLE
VOLATILE
These attributes inform the system whether it is safe to replace multiple evaluations of the function with a single evaluation, for run-time optimization. At most one choice should be specified. If none of these appear, VOLATILE is the default assumption.

IMMUTABLE indicates that the function always returns the same result when given the same argument values; that is, it does not do database lookups or otherwise use information not directly present in its argument list. If this option is given, any call of the function with all-constant arguments can be immediately replaced with the function value.

STABLE indicates that within a single table scan the function will consistently return the same result for the same argument values, but that its result could change across SQL statements. This is the appropriate selection for functions whose results depend on database lookups, parameter variables (such as the current time zone), etc. Also note that the current_timestamp family of functions qualify as stable, since their values do not change within a transaction.

VOLATILE indicates that the function value can change even within a single table scan, so no optimizations can be made. Relatively few database functions are volatile in this sense; some examples are random(), currval(), timeofday(). Note that any function that has side-effects must be classified volatile, even if its result is quite predictable, to prevent calls from being optimized away; an example is setval().

CALLED ON NULL INPUT
RETURNS NULL ON NULL INPUT
STRICT
CALLED ON NULL INPUT (the default) indicates that the function will be called normally when some of its arguments are null. It is then the function author's responsibility to check for null values if necessary and respond appropriately.

RETURNS NULL ON NULL INPUT or STRICT indicates that the function always returns null whenever any of its arguments are null. If this parameter is specified, the function is not executed when there are null arguments; instead a null result is assumed automatically.

[EXTERNAL] SECURITY INVOKER
[EXTERNAL] SECURITY DEFINER
SECURITY INVOKER indicates that the function is to be executed with the privileges of the user that calls it. That is the default. SECURITY DEFINER specifies that the function is to be executed with the privileges of the user that created it.

The key word EXTERNAL is present for SQL conformance but is optional since, unlike in SQL, this feature does not only apply to external functions.

definition
A string defining the function; the meaning depends on the language. It may be an internal function name, the path to an object file, an SQL command, or text in a procedural language.
obj_file, link_symbol
This form of the AS clause is used for dynamically loadable C language functions when the function name in the C language source code is not the same as the name of the SQL function. The string obj_file is the name of the file containing the dynamically loadable object, and link_symbol is the function's link symbol, that is, the name of the function in the C language source code. If the link symbol is omitted, it is assumed to be the same as the name of the SQL function being defined.
attribute
The historical way to specify optional pieces of information about the function. The following attributes may appear here:
isStrict
Equivalent to STRICT or RETURNS NULL ON NULL INPUT
isCachable
isCachable is an obsolete equivalent of IMMUTABLE; it's still accepted for backwards-compatibility reasons.

Attribute names are not case-sensitive.  

NOTES

Refer to the section called ``User-Defined Functions'' in the documentation for further information on writing functions.

The full SQL type syntax is allowed for input arguments and return value. However, some details of the type specification (e.g., the precision field for type numeric) are the responsibility of the underlying function implementation and are silently swallowed (i.e., not recognized or enforced) by the CREATE FUNCTION command.

PostgreSQL allows function overloading; that is, the same name can be used for several different functions so long as they have distinct argument types. However, the C names of all functions must be different, so you must give overloaded C functions different C names (for example, use the argument types as part of the C names).

When repeated CREATE FUNCTION calls refer to the same object file, the file is only loaded once. To unload and reload the file (perhaps during development), use the LOAD [load(7)] command.

Use DROP FUNCTION to remove user-defined functions.

Any single quotes or backslashes in the function definition must be escaped by doubling them.

To be able to define a function, the user must have the USAGE privilege on the language.  

EXAMPLES

Here is a trivial example to help you get started. For more information and examples, see the section called ``User-Defined Functions'' in the documentation.

CREATE FUNCTION add(integer, integer) RETURNS integer
    AS 'select $1 + $2;'
    LANGUAGE SQL
    IMMUTABLE
    RETURNS NULL ON NULL INPUT;

COMPATIBILITY

A CREATE FUNCTION command is defined in SQL99. The PostgreSQL version is similar but not fully compatible. The attributes are not portable, neither are the different available languages.  

SEE ALSO

ALTER FUNCTION [alter_function(7)], DROP FUNCTION [drop_function(7)], GRANT [grant(7)], LOAD [load(7)], REVOKE [revoke(7)], createlang(1)

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

2011-08-24 10:46:36

CREATE AGGR中文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: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 14:22:11

DROP FUNCTI中文man

2011-08-24 10:53:20

CREATE CONS中文man

2011-08-24 11:26:46

CREATE OPER中文man
點贊
收藏

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

主站蜘蛛池模板: 男女啪啪网址 | 逼逼视频 | 精品九九在线 | 日韩欧美一级精品久久 | 成人在线观看免费观看 | www.天天操 | 亚洲国产成人在线 | 国产精品久久久久久久久久免费 | 久久久久久一区 | 欧美理论在线观看 | 精品影视 | 亚洲国产精品va在线看黑人 | 欧美日韩国产一区二区 | 欧美日韩不卡 | 亚洲欧美日韩国产综合 | 国产美女一区 | 欧美一区二区三区电影 | 盗摄精品av一区二区三区 | 亚洲福利| 欧美视频在线播放 | 国产精品久久久久久久久久尿 | 国产视频中文字幕 | 精品在线一区 | 亚洲国产精品一区二区三区 | 91视频亚洲 | 国产成人精品久久二区二区91 | 国产精品欧美精品 | 美国十次成人欧美色导视频 | 日韩一区二区三区视频 | 欧美性一区二区三区 | 欧美精品一区二区三区四区五区 | 午夜99| 亚洲综合二区 | 国产激情在线 | 免费久久精品视频 | 欧美群妇大交群中文字幕 | 热久久免费视频 | 久久国产亚洲 | 国产午夜在线 | 色香蕉在线 | 欧美日韩不卡合集视频 |