--- title: "Structure of PL/pgSQL" id: plpgsql-structure pg_version: "20devel" --- ## 41.2. Structure of PL/pgSQL Functions written in PL/pgSQL are defined to the server by executing [CREATE FUNCTION](sql-createfunction.md) commands. Such a command would normally look like, say, CREATE FUNCTION somefunc(integer, text) RETURNS integer AS '`function body text`' LANGUAGE plpgsql; The function body is simply a string literal so far as `CREATE FUNCTION` is concerned. It is often helpful to use dollar quoting (see [Section 4.1.2.4](sql-syntax-lexical.md#sql-syntax-dollar-quoting)) to write the function body, rather than the normal single quote syntax. Without dollar quoting, any single quotes or backslashes in the function body must be escaped by doubling them. Almost all the examples in this chapter use dollar-quoted literals for their function bodies. PL/pgSQL is a block-structured language. The complete text of a function body must be a *block*. A block is defined as: ``` <