PostgreSQL: Execute PL/pgSQL Code on the Spot


In Oracle Database, we can use PL/SQL and create stored procedure and functions. As for PostgreSQL, we can use and create function.

Here, we write the way to execute PL/pgSQL on the spot, without creating function.

Environment

  • Client: version 9.6
  • Server: version 9.3

How to Do

Use DO.

If you write like aboce, PL/pgSQL is used for code processor and execute the code immediately. When we use other language such as PL/Tcl, PL/TclU, PL/Perl, PL/PerlU, PL/PythonU, write the language just after DO, like DO plperl.

Example

DO statement is introduced from PostgreSQL 9.0.