CREATE_LANGUAGE(7)

๐Ÿ’… CREATE_LANGUAGE(7) โ€” like, the whole entire manual page for CREATE LANGUAGE, bestie

okay so this is the PostgreSQL 18.6 Documentation page for CREATE LANGUAGE, and I'm gonna explain it to you like we're texting at 2am, but every single fact stays exactly where it was. no cap. ๐Ÿซถ


โœจ NAME โœจ

CREATE_LANGUAGE โ€” define a new procedural language ๐Ÿ‘‘


๐ŸŒธ SYNOPSIS ๐ŸŒธ

CREATE [ OR REPLACE ] [ TRUSTED ] [ PROCEDURAL ] LANGUAGE name
    HANDLER call_handler [ INLINE inline_handler ] [ VALIDATOR valfunction ]
CREATE [ OR REPLACE ] [ TRUSTED ] [ PROCEDURAL ] LANGUAGE name

๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

CREATE LANGUAGE registers a new procedural language with a PostgreSQL database. and then?? then functions and procedures can be defined in this new language. that's the whole point bestie, it's giving gateway. ๐ŸŒˆ

CREATE LANGUAGE effectively associates the language name with handler function(s) that are responsible for executing functions written in the language. if you wanna know more about language handlers, go read Chapter 57. i'm not summarising it, go read it. ๐Ÿ“–

CREATE OR REPLACE LANGUAGE will either create a new language, or replace an existing definition. so if the language already exists, its parameters get updated according to the command โ€” but the language's ownership and permissions settings do not change, and any existing functions written in the language are assumed to still be valid. like, we're trusting them. bold of us. ๐Ÿ’€

One must have the PostgreSQL superuser privilege to register a new language or change an existing language's parameters. HOWEVER โ€” and this is the cute part โ€” once the language is created it is valid to assign ownership of it to a non-superuser, who may then drop it, change its permissions, rename it, or assign it to a new owner.

โš ๏ธ Do not, however, assign ownership of the underlying C functions to a non-superuser; that would create a privilege escalation path for that user. that's a yikes, do not do that. ๐Ÿšจ

The form of CREATE LANGUAGE that does not supply any handler function is obsolete. for backwards compatibility with old dump files, it is interpreted as CREATE EXTENSION. That will work if the language has been packaged into an extension of the same name, which is the conventional way to set up procedural languages. iconic behaviour tbh. โœจ


๐ŸŽ€ PARAMETERS ๐ŸŽ€

  • TRUSTED โ€” TRUSTED specifies that the language does not grant access to data that the user would not otherwise have. If this key word is omitted when registering the language, only users with the PostgreSQL superuser privilege can use this language to create new functions. so like, trust issues but make it SQL. ๐Ÿ”’
  • PROCEDURAL โ€” This is a noise word. literally just noise. it's there, it does nothing, it's the group chat member who never types. ๐Ÿ™ˆ
  • name โ€” The name of the new procedural language. The name must be unique among the languages in the database. no duplicates bestie, we don't do that here. ๐Ÿ’…
  • HANDLER call_handler โ€” call_handler is the name of a previously registered function that will be called to execute the procedural language's functions. The call handler for a procedural language must be written in a compiled language such as C with version 1 call convention and registered with PostgreSQL as a function taking no arguments and returning the language_handler type โ€” a placeholder type that is simply used to identify the function as a call handler. it's giving name tag at a party. ๐Ÿท๏ธ
  • INLINE inline_handler โ€” inline_handler is the name of a previously registered function that will be called to execute an anonymous code block (DO command) in this language. If no inline_handler function is specified, the language does not support anonymous code blocks. ๐Ÿ˜ญ The handler function must take one argument of type internal, which will be the DO command's internal representation, and it will typically return void. The return value of the handler is ignored. yeah. ignored. we don't look at it. ๐Ÿ™ˆ
  • VALIDATOR valfunction โ€” valfunction is the name of a previously registered function that will be called when a new function in the language is created, to validate the new function. If no validator function is specified, then a new function will not be checked when it is created. free-range functions, no vibe check. The validator function must take one argument of type oid, which will be the OID of the to-be-created function, and will typically return void.

A validator function would typically inspect the function body for syntactical correctness, but it can also look at other properties of the function โ€” for example, if the language cannot handle certain argument types. To signal an error, the validator function should use the ereport() function. The return value of the function is ignored. again. ignored. it's fine. it's fine!! ๐Ÿ˜Œ


๐Ÿ’– NOTES ๐Ÿ’–

Use DROP LANGUAGE to drop procedural languages. bye bestie ๐Ÿ‘‹

The system catalog pg_language (see Section 52.29) records information about the currently installed languages. Also, the psql command \dL lists the installed languages. screenshot that, it's useful. ๐Ÿ“ธ

To create functions in a procedural language, a user must have the USAGE privilege for the language. By default, USAGE is granted to PUBLIC (i.e., everyone) for trusted languages. This can be revoked if desired. your house, your rules. ๐Ÿ 

Procedural languages are local to individual databases. However, a language can be installed into the template1 database, which will cause it to be available automatically in all subsequently-created databases. main character energy for template1 honestly. ๐Ÿ‘‘


โญ EXAMPLES โญ

A minimal sequence for creating a new procedural language is:

CREATE FUNCTION plsample_call_handler() RETURNS language_handler
    AS '$libdir/plsample'
    LANGUAGE C;
CREATE LANGUAGE plsample
    HANDLER plsample_call_handler;

Typically that would be written in an extension's creation script, and users would do this to install the extension:

CREATE EXTENSION plsample;

see how clean that is?? the glow up is real. โœจ๐Ÿฆ‹


๐Ÿ”ฅ COMPATIBILITY ๐Ÿ”ฅ

CREATE LANGUAGE is a PostgreSQL extension. it's ours, we made it, we're keeping it. ๐Ÿ’…


๐ŸŒˆ SEE ALSO ๐ŸŒˆ


and that's the page!! ๐Ÿ’œ this was PostgreSQL 18.6 documentation, dated 2026, for CREATE LANGUAGE(7) โ€” mwah, ate, no crumbs left. go forth and register your procedural languages responsibly, bestie. ๐ŸŽ€โœจ๐Ÿซถ