DO defines a code block that executes syntax.
Required privileges
- To define a
DOblock with a , a user must haveUSAGEprivilege on the user-defined type.
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
DO defines a code block that executes syntax.
DO block with a , a user must have USAGE privilege on the user-defined type.| Parameter | Description |
|---|---|
routine_body_str | The body of the code block. |
DO blockDO $$
DECLARE
x INT := 10;
y INT := 5;
result INT;
BEGIN
result := x + y;
RAISE NOTICE 'The sum of % and % is %', x, y, result;
END $$;
NOTICE: The sum of 10 and 5 is 15
DO
DO blockDO $$
DECLARE
counter INT := 1;
BEGIN
WHILE counter <= 5 LOOP
RAISE NOTICE 'Counter: %', counter;
counter := counter + 1;
END LOOP;
END $$;
NOTICE: Counter: 1
NOTICE: Counter: 2
NOTICE: Counter: 3
NOTICE: Counter: 4
NOTICE: Counter: 5
DO
DO blockDO $$
DECLARE
sum_result INT;
BEGIN
WITH numbers AS (
SELECT generate_series(1, 5) AS num
)
SELECT sum(num) INTO sum_result
FROM numbers;
RAISE NOTICE 'Sum of numbers 1-5: %', sum_result;
END $$;
NOTICE: Sum of numbers 1-5: 15
DO
