MFS401 : Table of Contents

Chapter 3

Lesson 3

RPC Wonders: Improving with Postgres Functions


Introduction to Postgres functions

PLPGSQL programming syntactic structure


Controlling access within Postgres functions

Polymorphic functions using function overloading

Integrating logic using transaction control

Quiz it to win it

Take the quiz

5 Questions
12 XP

Functions are a fundamental building block in programming. They encapsulate complex logic into reusable modules, leading to cleaner, more maintainable code.

With a database function, we can combine multiple database operations into one function and then execute that as a single transaction. Most of what functions do can still be done by individual queries. However, by combining them into a function, we can take advantage of reusability, atomicity, and access control over the whole function.

The most crucial among these is atomicity. That is, a function carrying out multiple operations will either execute all or none at all. Atomicity is essential in the context of database operations since failed database operations — particularly write operations — may lead to data inconsistencies.

Moreover, database calls perform the best if done closest to the data. Database functions are executed on the database server — it is as close to data as possible.

Note that functions in a database do not necessarily need to be pure database operations. They can also be utility functions — for example, inbuilt functions in Postgres such as avg, random, count, etc.

In this lesson, we dive deep into Postgres functions and how to use Supabase to create, maintain, and execute database functions in Postgres.

Get started for free today!

No commitments. No contracts. Enjoy all features for a day — join in just three clicks!

No credit card required.

Quiz it to win it

Complete this quiz successfully to proceed to the next lesson and win upto 12XP.

Start quiz for this lesson

Completing this quiz will get you

+12 Experience Points

+5% course progress