PostgreSQL Stored Procedures Tutorials and Examples

PostgreSQL allows you to extend its functionality with user defined functions by using various procedural languages such as PL/pgSQL, C, Perl, Python, and Tcl. These user defined functions are terms as Stored Procedures in PostgreSQL. Stored procedures allow you to create your custom functions and reuse them in applications or workflows in other databases.

Stored procedures in PostgreSQL: How to create a stored procedure and invoke it?

Moumita Ray · November 15, 2019

A stored procedure is basically a set of precompiled SQL and procedural statements (declarations, assignments, loops, etc.) that is stored on the database server and can be invoked using the SQL interface to perform a special operation.

Everything you need to know about Postgres stored procedures and functions

Thom Brown · December 6, 2019

This article reviews the differences between stored procedures and functions in Postgres and the types of functionality they provide.

How to raise errors and report messages within stored procedures and functions

Rajkumar Raghuwanshi · December 13, 2019

This article discusses the RAISE command for reporting errors, warnings, and other report messages within stored procedures and functions in PostgreSQL. Levels of error messages are covered along with settings for specifying their display to the client or log.

How to declare variables in PL/pgSQL stored procedures

Rajkumar Raghuwanshi · December 19, 2019

This article covers how stored procedures can make use of variables to be more functional and useful. After defining PL/pgSQL, stored procedures, and variables, it provides examples of how variables can be used.

How to develop a user-defined function in PostgreSQL stored procedures

Tushar Ahuja · December 19, 2019

This article covers how to create user-defined functions using PL/pgSQL procedural language in PostgreSQL. It introduces user-defined functions and gives examples of their use in different scenarios: PL/pgSQL; User-defined functions and procedures; CREATE FUNCTION statement syntax; and Examples of user-defined functions.

10 Examples of PostgreSQL Stored Procedures

Ranjeet Dhumal · January 8, 2020

This article provides ten examples of stored procedures in PostgreSQL.

How to work with control structures in PostgreSQL stored procedures: Using IF, CASE, and LOOP statements

Arun Gavhane · February 12, 2020

This article reviews control structures that can be used in PostgreSQL stored procedures, with syntax and examples provided for each.

How to call PostgreSQL stored procedures from a PHP application

Abbas Butt · February 19, 2020

This tutorial provides instructions and an example for calling a PostgreSQL stored procedure from a PHP application.

Get Postgres tips & tricks

Subscribe to our newsletter to get advanced Postgres how-tos.

Related Tutorials

Featured Webinar

Programming the SQL Way with Common Table Expression

This webinar will compare jquery and SQL/JSON by discussing: The similarities and differences between the two features, the equivalent functionality where they aren't identical, and examples of how they compare in practice

Watch Now

Introducing Postgres Pulse Live

Free To Attend: Every Monday 11AM EDT

A weekly blog and live video forum series built to offer insight into how we analyze problems and develop solutions using Postgres.

More About Postgres Pulse Live

6 Things a Developer Should Know About Postgres

In this tech guide, we describe the six things a developer should know about in terms of how easy it is to install, work with, and deploy Postgres as well as the unique capabilities and wide range of features that Postgres offers.

Download Now