1
1
<!--
2
- $PostgreSQL: pgsql/doc/src/sgml/ref/create_function.sgml,v 1.91 2010/02/25 22:24:00 momjian Exp $
2
+ $PostgreSQL: pgsql/doc/src/sgml/ref/create_function.sgml,v 1.92 2010/03/03 03:14:08 momjian Exp $
3
3
-->
4
4
5
5
<refentry id="SQL-CREATEFUNCTION">
@@ -46,6 +46,10 @@ CREATE [ OR REPLACE ] FUNCTION
46
46
<command>CREATE FUNCTION</command> defines a new function.
47
47
<command>CREATE OR REPLACE FUNCTION</command> will either create a
48
48
new function, or replace an existing definition.
49
+ To be able to define a function, the user must have the
50
+ <literal>USAGE</literal> privilege on the language.
51
+ </para>
52
+
49
53
</para>
50
54
51
55
<para>
@@ -69,6 +73,14 @@ CREATE [ OR REPLACE ] FUNCTION
69
73
<literal>OUT</> parameters except by dropping the function.)
70
74
</para>
71
75
76
+ <para>
77
+ When <command>CREATE OR REPLACE FUNCTION</> is used to replace an
78
+ existing function, the ownership and permissions of the function
79
+ do not change. All other function properties are assigned the
80
+ values specified or implied in the command. You must own the function
81
+ to replace it (this includes being a member of the owning role).
82
+ </para>
83
+
72
84
<para>
73
85
If you drop and then recreate a function, the new function is not
74
86
the same entity as the old; you will have to drop existing rules, views,
@@ -400,6 +412,18 @@ CREATE [ OR REPLACE ] FUNCTION
400
412
the parameter as the value to be applied when the function is entered.
401
413
</para>
402
414
415
+ <para>
416
+ If a <literal>SET</> clause is attached to a function, then
417
+ the effects of a <command>SET LOCAL</> command executed inside the
418
+ function for the same variable are restricted to the function: the
419
+ configuration parameter's prior value is still restored at function exit.
420
+ However, an ordinary
421
+ <command>SET</> command (without <literal>LOCAL</>) overrides the
422
+ <literal>SET</> clause, much as it would do for a previous <command>SET
423
+ LOCAL</> command: the effects of such a command will persist after
424
+ function exit, unless the current transaction is rolled back.
425
+ </para>
426
+
403
427
<para>
404
428
See <xref linkend="sql-set" endterm="sql-set-title"> and
405
429
<xref linkend="runtime-config">
@@ -417,6 +441,15 @@ CREATE [ OR REPLACE ] FUNCTION
417
441
language. It can be an internal function name, the path to an
418
442
object file, an SQL command, or text in a procedural language.
419
443
</para>
444
+
445
+ <para>
446
+ It is often helpful to use dollar quoting (see <xref
447
+ linkend="sql-syntax-dollar-quoting">) to write the function definition
448
+ string, rather than the normal single quote syntax. Without dollar
449
+ quoting, any single quotes or backslashes in the function definition must
450
+ be escaped by doubling them.
451
+ </para>
452
+
420
453
</listitem>
421
454
</varlistentry>
422
455
@@ -436,6 +469,14 @@ CREATE [ OR REPLACE ] FUNCTION
436
469
language source code. If the link symbol is omitted, it is assumed
437
470
to be the same as the name of the SQL function being defined.
438
471
</para>
472
+
473
+ <para>
474
+ When repeated <command>CREATE FUNCTION</command> calls refer to
475
+ the same object file, the file is only loaded once per session.
476
+ To unload and
477
+ reload the file (perhaps during development), start a new session.
478
+ </para>
479
+
439
480
</listitem>
440
481
</varlistentry>
441
482
@@ -479,23 +520,13 @@ CREATE [ OR REPLACE ] FUNCTION
479
520
480
521
</refsect1>
481
522
482
- <refsect1 id="sql-createfunction-notes">
483
- <title>Notes</title>
484
-
485
- <para>
486
- Refer to <xref linkend="xfunc"> for further information on writing
487
- functions.
488
- </para>
523
+ <para>
524
+ Refer to <xref linkend="xfunc"> for further information on writing
525
+ functions.
526
+ </para>
489
527
490
- <para>
491
- The full <acronym>SQL</acronym> type syntax is allowed for
492
- input arguments and return value. However, some details of the
493
- type specification (e.g., the precision field for
494
- type <type>numeric</type>) are the responsibility of the
495
- underlying function implementation and are silently swallowed
496
- (i.e., not recognized or
497
- enforced) by the <command>CREATE FUNCTION</command> command.
498
- </para>
528
+ <refsect1 id="sql-createfunction-overloading">
529
+ <title>Overloading</title>
499
530
500
531
<para>
501
532
<productname>PostgreSQL</productname> allows function
@@ -529,50 +560,19 @@ CREATE FUNCTION foo(int, int default 42) ...
529
560
function should be called.
530
561
</para>
531
562
532
- <para>
533
- When repeated <command>CREATE FUNCTION</command> calls refer to
534
- the same object file, the file is only loaded once per session.
535
- To unload and
536
- reload the file (perhaps during development), start a new session.
537
- </para>
538
-
539
- <para>
540
- Use <xref linkend="sql-dropfunction"
541
- endterm="sql-dropfunction-title"> to remove user-defined
542
- functions.
543
- </para>
544
-
545
- <para>
546
- It is often helpful to use dollar quoting (see <xref
547
- linkend="sql-syntax-dollar-quoting">) to write the function definition
548
- string, rather than the normal single quote syntax. Without dollar
549
- quoting, any single quotes or backslashes in the function definition must
550
- be escaped by doubling them.
551
- </para>
552
-
553
- <para>
554
- If a <literal>SET</> clause is attached to a function, then
555
- the effects of a <command>SET LOCAL</> command executed inside the
556
- function for the same variable are restricted to the function: the
557
- configuration parameter's prior value is still restored at function exit.
558
- However, an ordinary
559
- <command>SET</> command (without <literal>LOCAL</>) overrides the
560
- <literal>SET</> clause, much as it would do for a previous <command>SET
561
- LOCAL</> command: the effects of such a command will persist after
562
- function exit, unless the current transaction is rolled back.
563
- </para>
563
+ </refsect1>
564
564
565
- <para>
566
- To be able to define a function, the user must have the
567
- <literal>USAGE</literal> privilege on the language.
568
- </para>
565
+ <refsect1 id="sql-createfunction-notes">
566
+ <title>Notes</title>
569
567
570
568
<para>
571
- When <command>CREATE OR REPLACE FUNCTION</> is used to replace an
572
- existing function, the ownership and permissions of the function
573
- do not change. All other function properties are assigned the
574
- values specified or implied in the command. You must own the function
575
- to replace it (this includes being a member of the owning role).
569
+ The full <acronym>SQL</acronym> type syntax is allowed for
570
+ input arguments and return value. However, some details of the
571
+ type specification (e.g., the precision field for
572
+ type <type>numeric</type>) are the responsibility of the
573
+ underlying function implementation and are silently swallowed
574
+ (i.e., not recognized or
575
+ enforced) by the <command>CREATE FUNCTION</command> command.
576
576
</para>
577
577
578
578
<para>
0 commit comments