CREATE FUNCTION defines a new function.
CREATE OR REPLACE FUNCTION will either create a
new function, or replace an existing definition.
+ To be able to define a function, the user must have the
+ USAGE privilege on the language.
+
+
OUT> parameters except by dropping the function.)
+ When CREATE OR REPLACE FUNCTION> is used to replace an
+ existing function, the ownership and permissions of the function
+ do not change. All other function properties are assigned the
+ values specified or implied in the command. You must own the function
+ to replace it (this includes being a member of the owning role).
+
+
If you drop and then recreate a function, the new function is not
the same entity as the old; you will have to drop existing rules, views,
the parameter as the value to be applied when the function is entered.
+ If a SET> clause is attached to a function, then
+ the effects of a SET LOCAL> command executed inside the
+ function for the same variable are restricted to the function: the
+ configuration parameter's prior value is still restored at function exit.
+ However, an ordinary
+ SET> command (without LOCAL>) overrides the
+ SET> clause, much as it would do for a previous SET
+ LOCAL> command: the effects of such a command will persist after
+ function exit, unless the current transaction is rolled back.
+
+
See and
language. It can be an internal function name, the path to an
object file, an SQL command, or text in a procedural language.
+
+ It is often helpful to use dollar quoting (see
+ linkend="sql-syntax-dollar-quoting">) to write the function definition
+ string, rather than the normal single quote syntax. Without dollar
+ quoting, any single quotes or backslashes in the function definition must
+ be escaped by doubling them.
+
+
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.
+
+ When repeated CREATE FUNCTION calls refer to
+ the same object file, the file is only loaded once per session.
+ To unload and
+ reload the file (perhaps during development), start a new session.
+
+
-
-
Notes
-
- Refer to for further information on writing
- functions.
-
+ Refer to 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.
-
+
+
Overloading
PostgreSQL allows function
function should be called.
- When repeated CREATE FUNCTION calls refer to
- the same object file, the file is only loaded once per session.
- To unload and
- reload the file (perhaps during development), start a new session.
-
-
- Use
- endterm="sql-dropfunction-title"> to remove user-defined
- functions.
-
-
- It is often helpful to use dollar quoting (see
- linkend="sql-syntax-dollar-quoting">) to write the function definition
- string, rather than the normal single quote syntax. Without dollar
- quoting, any single quotes or backslashes in the function definition must
- be escaped by doubling them.
-
-
- If a SET> clause is attached to a function, then
- the effects of a SET LOCAL> command executed inside the
- function for the same variable are restricted to the function: the
- configuration parameter's prior value is still restored at function exit.
- However, an ordinary
- SET> command (without LOCAL>) overrides the
- SET> clause, much as it would do for a previous SET
- LOCAL> command: the effects of such a command will persist after
- function exit, unless the current transaction is rolled back.
-
+
- To be able to define a function, the user must have the
- USAGE privilege on the language.
-
+
+
Notes
- When CREATE OR REPLACE FUNCTION> is used to replace an
- existing function, the ownership and permissions of the function
- do not change. All other function properties are assigned the
- values specified or implied in the command. You must own the function
- to replace it (this includes being a member of the owning role).
+ 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.