Doc: improve introductory information about procedures.
authorTom Lane
Wed, 10 Mar 2021 16:33:50 +0000 (11:33 -0500)
committerTom Lane
Wed, 10 Mar 2021 16:33:50 +0000 (11:33 -0500)
Clarify the discussion in "User-Defined Procedures", by laying out
the key differences between functions and procedures in a bulleted
list.  Notably, this avoids burying the lede about procedures being
able to do transaction control.  Make the back-link in the CREATE
FUNCTION reference page more prominent, and add one in CREATE
PROCEDURE.

Per gripe from Guyren Howe.  Thanks to David Johnston for discussion.

Discussion: https://postgr.es/m/BYAPR03MB4903C53A8BB7EFF5EA289674A6949@BYAPR03MB4903.namprd03.prod.outlook.com

doc/src/sgml/ref/create_function.sgml
doc/src/sgml/ref/create_procedure.sgml
doc/src/sgml/xfunc.sgml

index 97285b757841606fa1a77acd21babbf3b884ee10..1a80f7aaafb90038c7d8eec2c309e2d2765b1c41 100644 (file)
@@ -100,6 +100,11 @@ CREATE [ OR REPLACE ] FUNCTION
    To be able to create a function, you must have USAGE
    privilege on the argument types and the return type.
   
+
+  
+   Refer to  for further information on writing
+   functions.
+  
  
 
  
@@ -578,12 +583,6 @@ CREATE [ OR REPLACE ] FUNCTION
     
 
    
-
-   
-    Refer to  for further information on writing
-    functions.
-   
-
  
 
  
@@ -661,8 +660,7 @@ CREATE FUNCTION foo(int, int default 42) ...
   Examples
 
   
-   Here are some trivial examples to help you get started.  For more
-   information and examples, see .
+   Add two integers using a SQL function:
 
 CREATE FUNCTION add(integer, integer) RETURNS integer
     AS 'select $1 + $2;'
index d225695626cbf173a92b8acfc2b4127972676587..6c23cc2f6c7dd9be95ae2f7f3707965bc4e5976f 100644 (file)
@@ -76,6 +76,11 @@ CREATE [ OR REPLACE ] PROCEDURE
    To be able to create a procedure, you must have USAGE
    privilege on the argument types.
   
+
+  
+   Refer to  for further information on writing
+   procedures.
+  
  
 
  
index 0f60a4a0ab6ddcf614aed59028d33c375fa68718..8d403591939ebe4d0e655f1f7a78a30c217d9a19 100644 (file)
   
 
    
-    A procedure is a database object similar to a function.  The difference is
-    that a procedure does not return a value, so there is no return type
-    declaration.  While a function is called as part of a query or DML
-    command, a procedure is called in isolation using
-    the  command.  If the CALL command is not
-    part of an explicit transaction, a procedure in many server-side
-    languages can commit, rollback, and begin new transactions during
-    its execution, which is not possible in functions.
+    A procedure is a database object similar to a function.
+    The key differences are:
+
+    
+     
+      
+       Procedures are defined with the 
+       command, not CREATE FUNCTION.
+      
+     
+     
+      
+       Procedures do not return a function value; hence CREATE
+       PROCEDURE lacks a RETURNS clause.
+       However, procedures can instead return data to their callers via
+       output parameters.
+      
+     
+     
+      
+       While a function is called as part of a query or DML command, a
+       procedure is called in isolation using
+       the  command.
+      
+     
+     
+      
+       A procedure can commit or roll back transactions during its
+       execution (then automatically beginning a new transaction), so long
+       as the invoking CALL command is not part of an
+       explicit transaction block.  A function cannot do that.
+      
+     
+     
+      
+       Certain function attributes, such as strictness, don't apply to
+       procedures.  Those attributes control how the function is
+       used in a query, which isn't relevant to procedures.
+      
+     
+    
    
 
    
-    The explanations on how to define user-defined functions in the rest of
-    this chapter apply to procedures as well, except that
-    the  command is used instead, there is
-    no return type, and some other features such as strictness don't apply.
+    The explanations in the following sections about how to define
+    user-defined functions apply to procedures as well, except for the
+    points made above.