November 2019
Beginner to intermediate
470 pages
11h 59m
English
So far, we have written the most simple stored procedures possible, and also learned how to execute code. However, there is more to code execution than just full-blown functions. In addition to functions, PostgreSQL allows the use of anonymous code blocks. The idea is to run code that is needed only once. This kind of code execution is especially useful for dealing with administrative tasks. Anonymous code blocks don't take parameters and are not permanently stored in the database, since they don't have names.
Here is a simple example showing an anonymous code block in action:
test=# DO $$ BEGIN RAISE NOTICE 'current time: %', now(); END; $$ LANGUAGE 'plpgsql'; NOTICE: current time: 2016-12-12 15:25:50.678922+01 ...
Read now
Unlock full access