Skip to content

Commit f5aede3

Browse files
committed
Postgresql anonymous bloccks
1 parent 17481bd commit f5aede3

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

postgresql/anonymous-blocks.sql

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
-- DO starts an anonymous block, silly $$ are mandatory
2+
DO $$
3+
DECLARE str TEXT;
4+
BEGIN
5+
WITH names AS (
6+
SELECT 1 AS ID,
7+
'Tom' AS NAME
8+
UNION ALL
9+
SELECT 2,
10+
'Jane')
11+
SELECT name
12+
INTO str
13+
FROM NAMES
14+
WHERE id = 1;
15+
16+
RAISE EXCEPTION 'found row with name %', str;
17+
END $$;

0 commit comments

Comments
 (0)