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โTRUSTEDspecifies 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_handleris 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 thelanguage_handlertype โ 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_handleris the name of a previously registered function that will be called to execute an anonymous code block (DOcommand) in this language. If noinline_handlerfunction is specified, the language does not support anonymous code blocks. ๐ญ The handler function must take one argument of typeinternal, which will be theDOcommand's internal representation, and it will typically returnvoid. The return value of the handler is ignored. yeah. ignored. we don't look at it. ๐VALIDATOR valfunctionโvalfunctionis 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 typeoid, which will be the OID of the to-be-created function, and will typically returnvoid.
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 ๐
ALTER LANGUAGE(ALTER_LANGUAGE(7))CREATE FUNCTION(CREATE_FUNCTION(7))DROP LANGUAGE(DROP_LANGUAGE(7))GRANT(7)REVOKE(7)
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. ๐โจ๐ซถ
๐ฆ where this page comes from
- alpine 3.23: postgresql18-doc 18.6-r0 ยท PostgreSQL
- alpine 3.24: postgresql18-doc 18.6-r0 ยท PostgreSQL
- arch rolling: postgresql 18.6-4 ยท PostgreSQL
- fedora 43: postgresql 18.6-1.fc43 ยท PostgreSQL
- fedora 43: postgresql 18.6-1.fc43 ยท PostgreSQL
- fedora 44: postgresql 18.6-1.fc44 ยท PostgreSQL
- fedora 44: postgresql 18.6-1.fc44 ยท PostgreSQL
- nixos 26.05: postgresql 18.6
- ubuntu resolute: postgresql-client-18 18.6-0ubuntu0.26.04.1 ยท PostgreSQL
- ubuntu stonking: postgresql-client-18 18.6-3build2 ยท PostgreSQL
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms