CREATE EXTENSION
CREATE EXTENSION [ IF NOT EXISTS ] name [ WITH SCHEMA schema ];
Registers an extension available to the server. See Extension development.
Without WITH SCHEMA, the extension is installed in the first schema in
search_path; an explicitly named schema must already exist. Extensions do not
create a private schema automatically. For example:
CREATE SCHEMA spatial;
CREATE EXTENSION amphi_gis WITH SCHEMA spatial;
Installs are recorded in sys.extension, including the extension name,
installation schema, and package version. The catalog survives restarts, and
ampdump emits CREATE EXTENSION before dependent objects. Restore requires the
same extension to be available on the target; the installed version is the
package version available there. Installs created before explicit registration
are not inferred or migrated automatically. Secrets and external connections
remain outside logical dumps.
PLAmphi
plamphi provides the PLAmphi procedural language. After installation it can
be inspected through sys.language and used in DO blocks:
CREATE EXTENSION plamphi;
DO LANGUAGE plamphi AS $$
print(1 + 2);
$$;
DO supports scalar expressions, print, and parameterized SQL templates with
SELECT, INSERT, UPDATE, and DELETE. A template must return one column
and at most one row; DML uses RETURNING. Each ${expression} becomes a bound
SQL parameter. Execution shares the session transaction, and transaction {}
and write-bearing try/catch blocks use real savepoints.
print(value) emits a server notice; ampsql displays it on stderr.
A non-nullable scalar query that returns no rows fails with SQLSTATE 02000.
Example:
CREATE TABLE counters (value int4);
DO LANGUAGE plamphi AS $$
const next = sql<int>`INSERT INTO counters VALUES (${1}) RETURNING value`;
print(next);
$$;
Current limits: SQL cursors and afterCommit are not available; templates with
multiple columns, multiple rows, or utility commands are rejected. Parameter
and result types are limited to the scalar subset supported by the runtime.
Each block is limited to 100,000 step checks and 1,000,000 instructions.
statement_timeout, transaction_timeout, and session cancellation also
interrupt the block.