1/*-------------------------------------------------------------------------
4 * PostgreSQL LANGUAGE support code.
6 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
10 * src/backend/commands/proclang.c
12 *-------------------------------------------------------------------------
39 const char *languageName =
stmt->plname;
49 bool nulls[Natts_pg_language];
50 bool replaces[Natts_pg_language];
65 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
66 errmsg(
"must be superuser to create custom procedural language")));
69 * Lookup the PL handler function and check that it is of the expected
75 if (funcrettype != LANGUAGE_HANDLEROID)
77 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
78 errmsg(
"function %s must return type %s",
81 /* validate the inline function */
84 funcargtypes[0] = INTERNALOID;
86 /* return value is ignored, so we don't check the type */
91 /* validate the validator function */
92 if (
stmt->plvalidator)
94 funcargtypes[0] = OIDOID;
96 /* return value is ignored, so we don't check the type */
101 /* ok to create it */
105 /* Prepare data to be inserted */
107 memset(nulls,
false,
sizeof(nulls));
108 memset(replaces,
true,
sizeof(replaces));
118 nulls[Anum_pg_language_lanacl - 1] =
true;
120 /* Check for pre-existing definition */
127 /* There is one; okay to replace it? */
131 errmsg(
"language \"%s\" already exists", languageName)));
133 /* This is currently pointless, since we already checked superuser */
141 * Do not change existing oid, ownership or permissions. Note
142 * dependency-update code below has to agree with this decision.
144 replaces[Anum_pg_language_oid - 1] =
false;
145 replaces[Anum_pg_language_lanowner - 1] =
false;
146 replaces[Anum_pg_language_lanacl - 1] =
false;
152 langoid = oldform->oid;
158 /* Creating a new language */
160 Anum_pg_language_oid);
168 * Create dependencies for the new language. If we are updating an
169 * existing language, first delete any existing pg_depend entries.
170 * (However, since we are not changing ownership or permissions, the
171 * shared dependencies do *not* need to change, and we leave them alone.)
173 myself.
classId = LanguageRelationId;
180 /* dependency on owner of language */
185 /* dependency on extension */
190 /* dependency on the PL handler function */
194 /* dependency on the inline handler function, if any */
201 /* dependency on the validator function, if any */
211 /* Post creation hook for new procedural language */
220 * get_language_oid - given a language name, look up the OID
222 * If missing_ok is false, throw an error if language name not found. If
223 * true, just return InvalidOid.
234 (
errcode(ERRCODE_UNDEFINED_OBJECT),
235 errmsg(
"language \"%s\" does not exist", langname)));
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
bool object_ownercheck(Oid classid, Oid objectid, Oid roleid)
static Datum values[MAXATTR]
#define OidIsValid(objectId)
Oid GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)
void record_object_address_dependencies(const ObjectAddress *depender, ObjectAddresses *referenced, DependencyType behavior)
void add_exact_object_address(const ObjectAddress *object, ObjectAddresses *addrs)
ObjectAddresses * new_object_addresses(void)
void free_object_addresses(ObjectAddresses *addrs)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
Assert(PointerIsAligned(start, uint64))
HeapTuple heap_modify_tuple(HeapTuple tuple, TupleDesc tupleDesc, const Datum *replValues, const bool *replIsnull, const bool *doReplace)
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
#define HeapTupleIsValid(tuple)
static void * GETSTRUCT(const HeapTupleData *tuple)
void CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
void CatalogTupleInsert(Relation heapRel, HeapTuple tup)
Oid get_func_rettype(Oid funcid)
void namestrcpy(Name name, const char *str)
char * NameListToString(const List *names)
#define InvokeObjectPostCreateHook(classId, objectId, subId)
#define ObjectAddressSet(addr, class_id, object_id)
Oid LookupFuncName(List *funcname, int nargs, const Oid *argtypes, bool missing_ok)
long deleteDependencyRecordsFor(Oid classId, Oid objectId, bool skipExtensionDeps)
void recordDependencyOnCurrentExtension(const ObjectAddress *object, bool isReplace)
FormData_pg_language * Form_pg_language
void recordDependencyOnOwner(Oid classId, Oid objectId, Oid owner)
static Datum PointerGetDatum(const void *X)
static Datum BoolGetDatum(bool X)
static Datum ObjectIdGetDatum(Oid X)
static Datum NameGetDatum(const NameData *X)
static Datum CStringGetDatum(const char *X)
Oid get_language_oid(const char *langname, bool missing_ok)
ObjectAddress CreateProceduralLanguage(CreatePLangStmt *stmt)
#define RelationGetDescr(relation)
#define ERRCODE_DUPLICATE_OBJECT
void ReleaseSysCache(HeapTuple tuple)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
#define GetSysCacheOid1(cacheId, oidcol, key1)
void table_close(Relation relation, LOCKMODE lockmode)
Relation table_open(Oid relationId, LOCKMODE lockmode)