AvailableIncluded in beta access

Micro-course · Intermediate / advanced

PostgreSQL functions and procedures

Encapsulate database-side logic while understanding its cost and alternatives.

90 minPostgreSQL · PL/pgSQL6 lessons · 9 activities available
Start the course

Free 30-day beta access · no payment · progress saved

The business problem

A sensitive transformation is duplicated in several applications.

What you will be able to do

Choose a function or procedure, define parameters and test effects.

  • Create a function
  • Create a procedure
  • Choose the right abstraction
  • Test errors

Scope of this micro-course

This micro-course targets one focused skill. It does not replace a complete path or server administration training.

Prerequisites

  • SQL queries
  • Transactions
  • Basic types

Project and practice

9 verified exercises are available. Validation is based on the programme exercises.

Focused path

Your programme, in order.

Content remains centralised: completing an activity here also updates the path that contains it.

Micro-lessons

  1. 01
    The problem to solve before syntax

    A UPDATE without WHERE can modify an entire table. A restarted import can also create duplicates if the uniqueness and conflict behavior are not defined.

    Open lesson
  2. 02
    Build a controllable method

    First write the SELECT that identifies the lines, run the change in a transaction, use RETURNING to observe the effects, and explicitly choose the conflict key of the UPSERT.

    Open lesson
  3. 03
    Check before interpreting

    Check the number of records returned before and after, check the returned values and test resuming the import. A safe operation is repeatable or explicitly non-repeatable.

    Open lesson
  4. 04
    The problem to solve before syntax

    A rule copied in several applications diverges. A function can centralize it close to the data, but logic that is too opaque or very coupled becomes difficult to test and deploy.

    Open lesson
  5. 05
    Build a controllable method

    A function returns a value or a set and can be used in a query depending on its properties. A procedure is called with CALL and is suitable for an imperative operation; exact capacities depend on the DBMS.

    Open lesson
  6. 06
    Check before interpreting

    Test NULL, limits, errors and execution rights. Qualify the pattern, avoid unnecessary dynamic SQL, and document volatility and side effects.

    Open lesson

Practical exercises

  1. 01
    Write testable PostgreSQL functions

    Create a multi-parameter function and test for normal values, NULL, and errors.

    Do exercise
  2. 02
    Create a billing business function 2 training scenario

    Encapsulate pure, typed, reusable computation. You must produce the result, check it on the source data and explain what it allows you to decide in this billing system.

    Do exercise
  3. 03
    Create a logistics business function 3 · training scenario

    Encapsulate pure, typed, reusable computation. You must produce the result, check it on the source data and explain what it allows you to decide in this national expeditions.

    Do exercise
  4. 04
    Create an HR business function 4 · training scenario

    Encapsulate pure, typed, reusable computation. You must produce the result, control it on the source data and explain what it allows you to decide in this human resources management.

    Do exercise
  5. 05
    Create an audit business function 5 training scenario

    Encapsulate pure, typed, reusable computation. You must produce the result, check it on the source data and explain what it allows you to decide in this audit log.

    Do exercise
  6. 06
    Edit data without losing control

    Practice writes, their edge cases and an idempotent operation.

    Do exercise
  7. 07
    Insert then update billing data 2 · training scenario

    Make two controlled changes and check the final state. You must produce the result, check it on the source data and explain what it allows you to decide in this billing system.

    Do exercise
  8. 08
    Insert then update logistics data 3 · training scenario

    Make two controlled changes and check the final state. You must produce the result, check it on the source data and explain what it allows you to decide in this national expeditions.

    Do exercise
  9. 09
    Insert then update HR data 4 · training scenario

    Make two controlled changes and check the final state. You must produce the result, control it on the source data and explain what it allows you to decide in this human resources management.

    Do exercise

Back to the full catalogue