You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/current/v24.1/create-function.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -31,7 +31,7 @@ If you grant `EXECUTE` privilege as a default privilege at the database level, n
31
31
Parameter | Description
32
32
----------|------------
33
33
`routine_create_name` | The name of the function.
34
-
`routine_param` | A comma-separated list of function parameters.
34
+
`routine_param` | A comma-separated list of function parameters, specifying the mode, name, and type.
35
35
`routine_return_type` | The type returned by the function.
36
36
`routine_body_str` | The body of the function. For allowed contents, see [User-Defined Functions]({% link {{ page.version.version }}/user-defined-functions.md %}#overview).
|`routine_create_name`| The name of the procedure. |
32
-
|`routine_param`| A comma-separated list of procedure parameters. |
33
-
|`routine_body_str`| The body of the procedure. For allowed contents, see [Stored Procedures]({% link {{ page.version.version }}/stored-procedures.md %}#structure). |
32
+
|`routine_param`| A comma-separated list of procedure parameters, specifying the mode, name, and type.|
33
+
|`routine_body_str`| The body of the procedure. For allowed contents, see [Stored Procedures]({% link {{ page.version.version }}/stored-procedures.md %}#structure). |
Copy file name to clipboardExpand all lines: src/current/v24.1/plpgsql.md
+32-3Lines changed: 32 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -40,7 +40,7 @@ At the highest level, a PL/pgSQL block looks like the following:
40
40
END
41
41
~~~
42
42
43
-
PL/pgSQL blocks can be nested. An optional label can be placed above each block. Block labels can be targeted by [`EXIT` statements](#exit-and-continue-statements).
43
+
PL/pgSQL blocks can be nested. An optional label can be placed above each block. Block labels can be targeted by [`EXIT` statements](#exit).
44
44
45
45
~~~sql
46
46
[ <<outer_block>> ]
@@ -217,7 +217,6 @@ IF condition THEN
217
217
218
218
`IF ... THEN ... ELSIF` executes statements if a boolean condition is true. If the condition is false, each `ELSIF` condition is evaluated until one is true. The corresponding `ELSIF` statements are executed. If no `ELSIF` conditions are true, no statements are executed unless an `ELSE` clause is included, in which case the `ELSE` statements are executed.
219
219
220
-
{% include_cached copy-clipboard.html %}
221
220
~~~sql
222
221
IF condition THEN
223
222
statements;
@@ -230,6 +229,14 @@ IF condition THEN
230
229
END IF;
231
230
~~~
232
231
232
+
`IF`, `ELSE`, and `ELSIF` conditions are not required to execute statements. You can exclude any statements or add a placeholder `NULL` statement.
233
+
234
+
~~~sql
235
+
IF condition THEN
236
+
NULL;
237
+
END IF;
238
+
~~~
239
+
233
240
For usage examples of conditional statements, see [Examples](#examples).
234
241
235
242
### Write loops
@@ -254,7 +261,9 @@ WHILE condition LOOP
254
261
255
262
For an example, see [Create a stored procedure that uses a `WHILE` loop]({% link {{ page.version.version }}/create-procedure.md %}#create-a-stored-procedure-that-uses-a-while-loop).
256
263
257
-
### `EXIT` and `CONTINUE` statements
264
+
### Control execution flow
265
+
266
+
#### `EXIT`
258
267
259
268
Add an `EXIT` statement to end a [loop](#write-loops). An `EXIT` statement can be combined with an optional `WHEN` boolean condition.
260
269
@@ -299,6 +308,18 @@ CREATE PROCEDURE p() AS $$
299
308
$$ LANGUAGE PLpgSQL;
300
309
~~~
301
310
311
+
#### `RETURN`
312
+
313
+
Add a `RETURN` statement to a routine with an `OUT` parameter or `VOID` return type to exit the routine immediately.
314
+
315
+
~~~sql
316
+
BEGIN
317
+
...
318
+
RETURN;
319
+
~~~
320
+
321
+
#### `CONTINUE`
322
+
302
323
Add a `CONTINUE` statement to end the current iteration of a [loop](#write-loops), skipping any statements below `CONTINUE` and beginning the next iteration of the loop.
303
324
304
325
A `CONTINUE` statement can be combined with an optional `WHEN` boolean condition. In the following example, if a `WHEN` condition is defined and met, then `CONTINUE` causes the loop to skip the second group of statements and begin again.
@@ -459,6 +480,14 @@ BEGIN
459
480
END
460
481
~~~
461
482
483
+
`WHEN` conditions are not required to execute statements. You can exclude any statements or add a placeholder `NULL` statement.
484
+
485
+
~~~sql
486
+
EXCEPTION
487
+
WHEN error THEN
488
+
NULL;
489
+
~~~
490
+
462
491
### Control transactions
463
492
464
493
Use a `COMMIT` or `ROLLBACK` statement within a PL/pgSQL [stored procedure]({% link {{ page.version.version }}/stored-procedures.md %}) to finish the current transaction and automatically start a new one.
0 commit comments