Loading topic
CREATE FUNCTION ... LANGUAGE plpgsql with a DECLARE section and a BEGIN ... END body. You should also be comfortable with SELECT ... INTO at a basic level. The chapter covers how to declare variables and constants, how scope and name resolution work6 min readCREATE FUNCTION ... LANGUAGE plpgsql with a BEGIN ... END body and call it from psql. It covers how to declare parameters, how callers pass arguments, and how a function or procedure sends values back through its parameter list.5 min readIF, CASE, and the loop forms of PL/pgSQL. It assumes you can write a basic CREATE FUNCTION ... LANGUAGE plpgsql body with a DECLARE section, assign with :=, and run it from psql. Looping over query results g4 min readCREATE FUNCTION ... LANGUAGE plpgsql block with DECLARE, BEGIN, and END. It also assumes you know how to declare variables and read parameters. You should be comfortable with SELECT, INSERT, UPDATE, and DELETE. The examples use `customers(id5 min readRETURNS clause, and that choice decides how you write the body and how callers use the function. It assumes you can write a basic function with CREATE FUNCTION, declare variables, and 5 min readFOR loop over a query, RETURN NEXT, and explicit cursors. It assumes you can already declare variables, use IF and LOOP, run SELECT INTO, check FOUND, and write a function with `RETURNS T5 min readSELECT INTO and FOUND, and read a CREATE FUNCTION statement. It covers how a function reports problems with RAISE, how an EXCEPTION block catches them, and what each choice costs.5 min readGRANT, and search_path at a basic level. The attributes sit between the signature 5 min readGET DIAGNOSTICS, and handle errors with EXCEPTION blocks, as covered in earlier chapters. It also assumes you know what a transaction is and what COMMIT and ROLLBACK do. Examples need PostgreSQL 11 or later. Where a feature ne6 min readSELECT INTO, and that you know the basics of SQL injection. You should also know how to read RAISE errors. Everything here builds on the way PL/pgSQL runs SQL statements.7 min readIF and RAISE, and run SQL in psql. It covers how trigger functions differ from ordinary functions, which special variables they receive, and the errors that come up most often. The target length is about 1,400 words.5 min readSELECT INTO, RETURN QUERY, and exception blocks. It also assumes you have read the chapters on function attributes, query loops, and dynamic SQL. Here you learn to find out whether a function is fast, to test it,8 min read