RANIARANIA Academy

Stored Procedures & PL/pgSQL

Write server-side database logic in PostgreSQL using PL/pgSQL. You will build functions that return scalars, rows and sets, write procedures with transaction control, handle errors with exception blocks and RAISE, and judge when logic belongs in the database rather than the application.

Watch the free preview

The anatomy of a PL/pgSQL function — free to watch, no account needed.

PostgreSQL ADVANCED · 150 min · Certificate on completion · 3 CPD points

What you'll learn

  • Write server-side database logic in PostgreSQL using PL/pgSQL functions and procedures
  • Declare and use variables, IF/CASE conditionals and every PL/pgSQL loop form correctly
  • Build functions that return scalar values, single rows and full result sets
  • Handle runtime errors with exception blocks and raise diagnostics with RAISE
  • Decide when to push logic into the database versus keeping it in the application

Syllabus

PL/pgSQL Structure and Variables
The anatomy of a PL/pgSQL functionFree preview15 min
Variables, assignment and SELECT INTO15 min
Control Flow — Conditionals and Loops
Conditionals with IF and CASE15 min
Loops — LOOP, WHILE, FOR and FOREACH15 min
Functions and Procedures
Functions returning scalars, rows and sets15 min
Procedures, CALL and transaction control15 min
Errors and Design Judgement
Exception handling and RAISE15 min
When to push logic into the database15 min
Lab — 10 Exercises & Solutions
Exercises 1–515 min
Exercises 6–1015 min