1997-10-28 16:11:45 +01:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* proclang.c
|
1997-10-28 16:11:45 +01:00
|
|
|
* PostgreSQL PROCEDURAL LANGUAGE support code.
|
|
|
|
*
|
2018-01-03 05:30:12 +01:00
|
|
|
* Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group
|
2001-06-13 23:44:41 +02:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
2010-09-20 22:08:53 +02:00
|
|
|
* src/backend/commands/proclang.c
|
2001-06-13 23:44:41 +02:00
|
|
|
*
|
1997-10-28 16:11:45 +01:00
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#include "postgres.h"
|
|
|
|
|
2005-09-08 22:07:42 +02:00
|
|
|
#include "access/genam.h"
|
1997-10-28 16:11:45 +01:00
|
|
|
#include "access/heapam.h"
|
2012-08-30 22:15:44 +02:00
|
|
|
#include "access/htup_details.h"
|
2002-07-12 20:43:19 +02:00
|
|
|
#include "catalog/dependency.h"
|
1999-11-22 18:56:41 +01:00
|
|
|
#include "catalog/indexing.h"
|
2010-11-25 17:48:49 +01:00
|
|
|
#include "catalog/objectaccess.h"
|
2012-05-31 05:47:57 +02:00
|
|
|
#include "catalog/pg_authid.h"
|
1997-10-28 16:11:45 +01:00
|
|
|
#include "catalog/pg_language.h"
|
2005-09-06 01:50:49 +02:00
|
|
|
#include "catalog/pg_namespace.h"
|
2005-09-08 22:07:42 +02:00
|
|
|
#include "catalog/pg_pltemplate.h"
|
1998-04-27 06:08:07 +02:00
|
|
|
#include "catalog/pg_proc.h"
|
2008-03-27 04:57:34 +01:00
|
|
|
#include "catalog/pg_proc_fn.h"
|
2002-05-22 19:21:02 +02:00
|
|
|
#include "catalog/pg_type.h"
|
2007-03-26 18:58:41 +02:00
|
|
|
#include "commands/dbcommands.h"
|
2002-04-15 07:22:04 +02:00
|
|
|
#include "commands/defrem.h"
|
2006-07-11 19:26:59 +02:00
|
|
|
#include "commands/proclang.h"
|
2001-06-13 23:44:41 +02:00
|
|
|
#include "miscadmin.h"
|
2002-04-09 22:35:55 +02:00
|
|
|
#include "parser/parse_func.h"
|
2009-07-12 19:12:34 +02:00
|
|
|
#include "parser/parser.h"
|
2007-03-26 18:58:41 +02:00
|
|
|
#include "utils/acl.h"
|
2000-05-28 19:56:29 +02:00
|
|
|
#include "utils/builtins.h"
|
2005-09-06 01:50:49 +02:00
|
|
|
#include "utils/fmgroids.h"
|
2002-04-09 22:35:55 +02:00
|
|
|
#include "utils/lsyscache.h"
|
2008-06-19 02:46:06 +02:00
|
|
|
#include "utils/rel.h"
|
1998-04-27 06:08:07 +02:00
|
|
|
#include "utils/syscache.h"
|
2008-03-26 22:10:39 +01:00
|
|
|
#include "utils/tqual.h"
|
1997-10-28 16:11:45 +01:00
|
|
|
|
|
|
|
|
2005-09-06 01:50:49 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
2005-09-08 22:07:42 +02:00
|
|
|
bool tmpltrusted; /* trusted? */
|
2007-03-26 18:58:41 +02:00
|
|
|
bool tmpldbacreate; /* db owner allowed to create? */
|
2005-09-08 22:07:42 +02:00
|
|
|
char *tmplhandler; /* name of handler function */
|
2009-09-23 01:43:43 +02:00
|
|
|
char *tmplinline; /* name of anonymous-block handler, or NULL */
|
2005-09-08 22:07:42 +02:00
|
|
|
char *tmplvalidator; /* name of validator function, or NULL */
|
|
|
|
char *tmpllibrary; /* path of shared library */
|
2005-09-06 01:50:49 +02:00
|
|
|
} PLTemplate;
|
|
|
|
|
Change many routines to return ObjectAddress rather than OID
The changed routines are mostly those that can be directly called by
ProcessUtilitySlow; the intention is to make the affected object
information more precise, in support for future event trigger changes.
Originally it was envisioned that the OID of the affected object would
be enough, and in most cases that is correct, but upon actually
implementing the event trigger changes it turned out that ObjectAddress
is more widely useful.
Additionally, some command execution routines grew an output argument
that's an object address which provides further info about the executed
command. To wit:
* for ALTER DOMAIN / ADD CONSTRAINT, it corresponds to the address of
the new constraint
* for ALTER OBJECT / SET SCHEMA, it corresponds to the address of the
schema that originally contained the object.
* for ALTER EXTENSION {ADD, DROP} OBJECT, it corresponds to the address
of the object added to or dropped from the extension.
There's no user-visible change in this commit, and no functional change
either.
Discussion: 20150218213255.GC6717@tamriel.snowman.net
Reviewed-By: Stephen Frost, Andres Freund
2015-03-03 18:10:50 +01:00
|
|
|
static ObjectAddress create_proc_lang(const char *languageName, bool replace,
|
2013-05-29 22:58:43 +02:00
|
|
|
Oid languageOwner, Oid handlerOid, Oid inlineOid,
|
|
|
|
Oid valOid, bool trusted);
|
2005-09-06 01:50:49 +02:00
|
|
|
static PLTemplate *find_language_template(const char *languageName);
|
|
|
|
|
1997-10-28 16:11:45 +01:00
|
|
|
/* ---------------------------------------------------------------------
|
|
|
|
* CREATE PROCEDURAL LANGUAGE
|
|
|
|
* ---------------------------------------------------------------------
|
|
|
|
*/
|
Change many routines to return ObjectAddress rather than OID
The changed routines are mostly those that can be directly called by
ProcessUtilitySlow; the intention is to make the affected object
information more precise, in support for future event trigger changes.
Originally it was envisioned that the OID of the affected object would
be enough, and in most cases that is correct, but upon actually
implementing the event trigger changes it turned out that ObjectAddress
is more widely useful.
Additionally, some command execution routines grew an output argument
that's an object address which provides further info about the executed
command. To wit:
* for ALTER DOMAIN / ADD CONSTRAINT, it corresponds to the address of
the new constraint
* for ALTER OBJECT / SET SCHEMA, it corresponds to the address of the
schema that originally contained the object.
* for ALTER EXTENSION {ADD, DROP} OBJECT, it corresponds to the address
of the object added to or dropped from the extension.
There's no user-visible change in this commit, and no functional change
either.
Discussion: 20150218213255.GC6717@tamriel.snowman.net
Reviewed-By: Stephen Frost, Andres Freund
2015-03-03 18:10:50 +01:00
|
|
|
ObjectAddress
|
1998-02-26 05:46:47 +01:00
|
|
|
CreateProceduralLanguage(CreatePLangStmt *stmt)
|
1997-10-28 16:11:45 +01:00
|
|
|
{
|
2005-09-06 01:50:49 +02:00
|
|
|
PLTemplate *pltemplate;
|
Change many routines to return ObjectAddress rather than OID
The changed routines are mostly those that can be directly called by
ProcessUtilitySlow; the intention is to make the affected object
information more precise, in support for future event trigger changes.
Originally it was envisioned that the OID of the affected object would
be enough, and in most cases that is correct, but upon actually
implementing the event trigger changes it turned out that ObjectAddress
is more widely useful.
Additionally, some command execution routines grew an output argument
that's an object address which provides further info about the executed
command. To wit:
* for ALTER DOMAIN / ADD CONSTRAINT, it corresponds to the address of
the new constraint
* for ALTER OBJECT / SET SCHEMA, it corresponds to the address of the
schema that originally contained the object.
* for ALTER EXTENSION {ADD, DROP} OBJECT, it corresponds to the address
of the object added to or dropped from the extension.
There's no user-visible change in this commit, and no functional change
either.
Discussion: 20150218213255.GC6717@tamriel.snowman.net
Reviewed-By: Stephen Frost, Andres Freund
2015-03-03 18:10:50 +01:00
|
|
|
ObjectAddress tmpAddr;
|
2005-09-06 01:50:49 +02:00
|
|
|
Oid handlerOid,
|
2009-09-23 01:43:43 +02:00
|
|
|
inlineOid,
|
2005-09-06 01:50:49 +02:00
|
|
|
valOid;
|
2002-09-21 20:39:26 +02:00
|
|
|
Oid funcrettype;
|
2005-03-29 05:01:32 +02:00
|
|
|
Oid funcargtypes[1];
|
1997-10-28 16:11:45 +01:00
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
2005-09-06 01:50:49 +02:00
|
|
|
* If we have template information for the language, ignore the supplied
|
|
|
|
* parameters (if any) and use the template information.
|
1997-10-28 16:11:45 +01:00
|
|
|
*/
|
2011-11-17 20:20:13 +01:00
|
|
|
if ((pltemplate = find_language_template(stmt->plname)) != NULL)
|
2002-09-21 20:39:26 +02:00
|
|
|
{
|
2005-10-15 04:49:52 +02:00
|
|
|
List *funcname;
|
2005-09-06 01:50:49 +02:00
|
|
|
|
2005-09-08 22:07:42 +02:00
|
|
|
/*
|
|
|
|
* Give a notice if we are ignoring supplied parameters.
|
|
|
|
*/
|
|
|
|
if (stmt->plhandler)
|
|
|
|
ereport(NOTICE,
|
|
|
|
(errmsg("using pg_pltemplate information instead of CREATE LANGUAGE parameters")));
|
|
|
|
|
2007-03-26 18:58:41 +02:00
|
|
|
/*
|
|
|
|
* Check permission
|
|
|
|
*/
|
|
|
|
if (!superuser())
|
|
|
|
{
|
|
|
|
if (!pltemplate->tmpldbacreate)
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
|
|
|
|
errmsg("must be superuser to create procedural language \"%s\"",
|
2011-11-17 20:20:13 +01:00
|
|
|
stmt->plname)));
|
2007-03-26 18:58:41 +02:00
|
|
|
if (!pg_database_ownercheck(MyDatabaseId, GetUserId()))
|
2017-12-02 15:26:34 +01:00
|
|
|
aclcheck_error(ACLCHECK_NOT_OWNER, OBJECT_DATABASE,
|
2007-03-26 18:58:41 +02:00
|
|
|
get_database_name(MyDatabaseId));
|
|
|
|
}
|
|
|
|
|
2002-09-21 20:39:26 +02:00
|
|
|
/*
|
2005-10-15 04:49:52 +02:00
|
|
|
* Find or create the handler function, which we force to be in the
|
|
|
|
* pg_catalog schema. If already present, it must have the correct
|
|
|
|
* return type.
|
2002-09-21 20:39:26 +02:00
|
|
|
*/
|
2005-09-08 22:07:42 +02:00
|
|
|
funcname = SystemFuncName(pltemplate->tmplhandler);
|
2005-09-06 01:50:49 +02:00
|
|
|
handlerOid = LookupFuncName(funcname, 0, funcargtypes, true);
|
|
|
|
if (OidIsValid(handlerOid))
|
2002-09-21 20:39:26 +02:00
|
|
|
{
|
2005-09-06 01:50:49 +02:00
|
|
|
funcrettype = get_func_rettype(handlerOid);
|
|
|
|
if (funcrettype != LANGUAGE_HANDLEROID)
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
|
2016-06-10 00:02:36 +02:00
|
|
|
errmsg("function %s must return type %s",
|
Phase 3 of pgindent updates.
Don't move parenthesized lines to the left, even if that means they
flow past the right margin.
By default, BSD indent lines up statement continuation lines that are
within parentheses so that they start just to the right of the preceding
left parenthesis. However, traditionally, if that resulted in the
continuation line extending to the right of the desired right margin,
then indent would push it left just far enough to not overrun the margin,
if it could do so without making the continuation line start to the left of
the current statement indent. That makes for a weird mix of indentations
unless one has been completely rigid about never violating the 80-column
limit.
This behavior has been pretty universally panned by Postgres developers.
Hence, disable it with indent's new -lpl switch, so that parenthesized
lines are always lined up with the preceding left paren.
This patch is much less interesting than the first round of indent
changes, but also bulkier, so I thought it best to separate the effects.
Discussion: https://postgr.es/m/E1dAmxK-0006EE-1r@gemulon.postgresql.org
Discussion: https://postgr.es/m/30527.1495162840@sss.pgh.pa.us
2017-06-21 21:35:54 +02:00
|
|
|
NameListToString(funcname), "language_handler")));
|
2002-09-21 20:39:26 +02:00
|
|
|
}
|
|
|
|
else
|
2005-09-06 01:50:49 +02:00
|
|
|
{
|
Change many routines to return ObjectAddress rather than OID
The changed routines are mostly those that can be directly called by
ProcessUtilitySlow; the intention is to make the affected object
information more precise, in support for future event trigger changes.
Originally it was envisioned that the OID of the affected object would
be enough, and in most cases that is correct, but upon actually
implementing the event trigger changes it turned out that ObjectAddress
is more widely useful.
Additionally, some command execution routines grew an output argument
that's an object address which provides further info about the executed
command. To wit:
* for ALTER DOMAIN / ADD CONSTRAINT, it corresponds to the address of
the new constraint
* for ALTER OBJECT / SET SCHEMA, it corresponds to the address of the
schema that originally contained the object.
* for ALTER EXTENSION {ADD, DROP} OBJECT, it corresponds to the address
of the object added to or dropped from the extension.
There's no user-visible change in this commit, and no functional change
either.
Discussion: 20150218213255.GC6717@tamriel.snowman.net
Reviewed-By: Stephen Frost, Andres Freund
2015-03-03 18:10:50 +01:00
|
|
|
tmpAddr = ProcedureCreate(pltemplate->tmplhandler,
|
|
|
|
PG_CATALOG_NAMESPACE,
|
|
|
|
false, /* replace */
|
|
|
|
false, /* returnsSet */
|
|
|
|
LANGUAGE_HANDLEROID,
|
|
|
|
BOOTSTRAP_SUPERUSERID,
|
|
|
|
ClanguageId,
|
|
|
|
F_FMGR_C_VALIDATOR,
|
|
|
|
pltemplate->tmplhandler,
|
|
|
|
pltemplate->tmpllibrary,
|
|
|
|
false, /* isAgg */
|
|
|
|
false, /* isWindowFunc */
|
|
|
|
false, /* security_definer */
|
|
|
|
false, /* isLeakProof */
|
|
|
|
false, /* isStrict */
|
|
|
|
PROVOLATILE_VOLATILE,
|
2015-09-16 21:38:47 +02:00
|
|
|
PROPARALLEL_UNSAFE,
|
Change many routines to return ObjectAddress rather than OID
The changed routines are mostly those that can be directly called by
ProcessUtilitySlow; the intention is to make the affected object
information more precise, in support for future event trigger changes.
Originally it was envisioned that the OID of the affected object would
be enough, and in most cases that is correct, but upon actually
implementing the event trigger changes it turned out that ObjectAddress
is more widely useful.
Additionally, some command execution routines grew an output argument
that's an object address which provides further info about the executed
command. To wit:
* for ALTER DOMAIN / ADD CONSTRAINT, it corresponds to the address of
the new constraint
* for ALTER OBJECT / SET SCHEMA, it corresponds to the address of the
schema that originally contained the object.
* for ALTER EXTENSION {ADD, DROP} OBJECT, it corresponds to the address
of the object added to or dropped from the extension.
There's no user-visible change in this commit, and no functional change
either.
Discussion: 20150218213255.GC6717@tamriel.snowman.net
Reviewed-By: Stephen Frost, Andres Freund
2015-03-03 18:10:50 +01:00
|
|
|
buildoidvector(funcargtypes, 0),
|
|
|
|
PointerGetDatum(NULL),
|
|
|
|
PointerGetDatum(NULL),
|
|
|
|
PointerGetDatum(NULL),
|
|
|
|
NIL,
|
|
|
|
PointerGetDatum(NULL),
|
2015-04-26 16:33:14 +02:00
|
|
|
PointerGetDatum(NULL),
|
Change many routines to return ObjectAddress rather than OID
The changed routines are mostly those that can be directly called by
ProcessUtilitySlow; the intention is to make the affected object
information more precise, in support for future event trigger changes.
Originally it was envisioned that the OID of the affected object would
be enough, and in most cases that is correct, but upon actually
implementing the event trigger changes it turned out that ObjectAddress
is more widely useful.
Additionally, some command execution routines grew an output argument
that's an object address which provides further info about the executed
command. To wit:
* for ALTER DOMAIN / ADD CONSTRAINT, it corresponds to the address of
the new constraint
* for ALTER OBJECT / SET SCHEMA, it corresponds to the address of the
schema that originally contained the object.
* for ALTER EXTENSION {ADD, DROP} OBJECT, it corresponds to the address
of the object added to or dropped from the extension.
There's no user-visible change in this commit, and no functional change
either.
Discussion: 20150218213255.GC6717@tamriel.snowman.net
Reviewed-By: Stephen Frost, Andres Freund
2015-03-03 18:10:50 +01:00
|
|
|
1,
|
|
|
|
0);
|
|
|
|
handlerOid = tmpAddr.objectId;
|
2005-09-06 01:50:49 +02:00
|
|
|
}
|
1997-10-28 16:11:45 +01:00
|
|
|
|
2009-09-23 01:43:43 +02:00
|
|
|
/*
|
2010-02-26 03:01:40 +01:00
|
|
|
* Likewise for the anonymous block handler, if required; but we don't
|
|
|
|
* care about its return type.
|
2009-09-23 01:43:43 +02:00
|
|
|
*/
|
|
|
|
if (pltemplate->tmplinline)
|
|
|
|
{
|
|
|
|
funcname = SystemFuncName(pltemplate->tmplinline);
|
|
|
|
funcargtypes[0] = INTERNALOID;
|
|
|
|
inlineOid = LookupFuncName(funcname, 1, funcargtypes, true);
|
|
|
|
if (!OidIsValid(inlineOid))
|
|
|
|
{
|
Change many routines to return ObjectAddress rather than OID
The changed routines are mostly those that can be directly called by
ProcessUtilitySlow; the intention is to make the affected object
information more precise, in support for future event trigger changes.
Originally it was envisioned that the OID of the affected object would
be enough, and in most cases that is correct, but upon actually
implementing the event trigger changes it turned out that ObjectAddress
is more widely useful.
Additionally, some command execution routines grew an output argument
that's an object address which provides further info about the executed
command. To wit:
* for ALTER DOMAIN / ADD CONSTRAINT, it corresponds to the address of
the new constraint
* for ALTER OBJECT / SET SCHEMA, it corresponds to the address of the
schema that originally contained the object.
* for ALTER EXTENSION {ADD, DROP} OBJECT, it corresponds to the address
of the object added to or dropped from the extension.
There's no user-visible change in this commit, and no functional change
either.
Discussion: 20150218213255.GC6717@tamriel.snowman.net
Reviewed-By: Stephen Frost, Andres Freund
2015-03-03 18:10:50 +01:00
|
|
|
tmpAddr = ProcedureCreate(pltemplate->tmplinline,
|
|
|
|
PG_CATALOG_NAMESPACE,
|
Phase 2 of pgindent updates.
Change pg_bsd_indent to follow upstream rules for placement of comments
to the right of code, and remove pgindent hack that caused comments
following #endif to not obey the general rule.
Commit e3860ffa4dd0dad0dd9eea4be9cc1412373a8c89 wasn't actually using
the published version of pg_bsd_indent, but a hacked-up version that
tried to minimize the amount of movement of comments to the right of
code. The situation of interest is where such a comment has to be
moved to the right of its default placement at column 33 because there's
code there. BSD indent has always moved right in units of tab stops
in such cases --- but in the previous incarnation, indent was working
in 8-space tab stops, while now it knows we use 4-space tabs. So the
net result is that in about half the cases, such comments are placed
one tab stop left of before. This is better all around: it leaves
more room on the line for comment text, and it means that in such
cases the comment uniformly starts at the next 4-space tab stop after
the code, rather than sometimes one and sometimes two tabs after.
Also, ensure that comments following #endif are indented the same
as comments following other preprocessor commands such as #else.
That inconsistency turns out to have been self-inflicted damage
from a poorly-thought-through post-indent "fixup" in pgindent.
This patch is much less interesting than the first round of indent
changes, but also bulkier, so I thought it best to separate the effects.
Discussion: https://postgr.es/m/E1dAmxK-0006EE-1r@gemulon.postgresql.org
Discussion: https://postgr.es/m/30527.1495162840@sss.pgh.pa.us
2017-06-21 21:18:54 +02:00
|
|
|
false, /* replace */
|
|
|
|
false, /* returnsSet */
|
Change many routines to return ObjectAddress rather than OID
The changed routines are mostly those that can be directly called by
ProcessUtilitySlow; the intention is to make the affected object
information more precise, in support for future event trigger changes.
Originally it was envisioned that the OID of the affected object would
be enough, and in most cases that is correct, but upon actually
implementing the event trigger changes it turned out that ObjectAddress
is more widely useful.
Additionally, some command execution routines grew an output argument
that's an object address which provides further info about the executed
command. To wit:
* for ALTER DOMAIN / ADD CONSTRAINT, it corresponds to the address of
the new constraint
* for ALTER OBJECT / SET SCHEMA, it corresponds to the address of the
schema that originally contained the object.
* for ALTER EXTENSION {ADD, DROP} OBJECT, it corresponds to the address
of the object added to or dropped from the extension.
There's no user-visible change in this commit, and no functional change
either.
Discussion: 20150218213255.GC6717@tamriel.snowman.net
Reviewed-By: Stephen Frost, Andres Freund
2015-03-03 18:10:50 +01:00
|
|
|
VOIDOID,
|
|
|
|
BOOTSTRAP_SUPERUSERID,
|
|
|
|
ClanguageId,
|
|
|
|
F_FMGR_C_VALIDATOR,
|
|
|
|
pltemplate->tmplinline,
|
|
|
|
pltemplate->tmpllibrary,
|
Phase 2 of pgindent updates.
Change pg_bsd_indent to follow upstream rules for placement of comments
to the right of code, and remove pgindent hack that caused comments
following #endif to not obey the general rule.
Commit e3860ffa4dd0dad0dd9eea4be9cc1412373a8c89 wasn't actually using
the published version of pg_bsd_indent, but a hacked-up version that
tried to minimize the amount of movement of comments to the right of
code. The situation of interest is where such a comment has to be
moved to the right of its default placement at column 33 because there's
code there. BSD indent has always moved right in units of tab stops
in such cases --- but in the previous incarnation, indent was working
in 8-space tab stops, while now it knows we use 4-space tabs. So the
net result is that in about half the cases, such comments are placed
one tab stop left of before. This is better all around: it leaves
more room on the line for comment text, and it means that in such
cases the comment uniformly starts at the next 4-space tab stop after
the code, rather than sometimes one and sometimes two tabs after.
Also, ensure that comments following #endif are indented the same
as comments following other preprocessor commands such as #else.
That inconsistency turns out to have been self-inflicted damage
from a poorly-thought-through post-indent "fixup" in pgindent.
This patch is much less interesting than the first round of indent
changes, but also bulkier, so I thought it best to separate the effects.
Discussion: https://postgr.es/m/E1dAmxK-0006EE-1r@gemulon.postgresql.org
Discussion: https://postgr.es/m/30527.1495162840@sss.pgh.pa.us
2017-06-21 21:18:54 +02:00
|
|
|
false, /* isAgg */
|
|
|
|
false, /* isWindowFunc */
|
|
|
|
false, /* security_definer */
|
|
|
|
false, /* isLeakProof */
|
Change many routines to return ObjectAddress rather than OID
The changed routines are mostly those that can be directly called by
ProcessUtilitySlow; the intention is to make the affected object
information more precise, in support for future event trigger changes.
Originally it was envisioned that the OID of the affected object would
be enough, and in most cases that is correct, but upon actually
implementing the event trigger changes it turned out that ObjectAddress
is more widely useful.
Additionally, some command execution routines grew an output argument
that's an object address which provides further info about the executed
command. To wit:
* for ALTER DOMAIN / ADD CONSTRAINT, it corresponds to the address of
the new constraint
* for ALTER OBJECT / SET SCHEMA, it corresponds to the address of the
schema that originally contained the object.
* for ALTER EXTENSION {ADD, DROP} OBJECT, it corresponds to the address
of the object added to or dropped from the extension.
There's no user-visible change in this commit, and no functional change
either.
Discussion: 20150218213255.GC6717@tamriel.snowman.net
Reviewed-By: Stephen Frost, Andres Freund
2015-03-03 18:10:50 +01:00
|
|
|
true, /* isStrict */
|
|
|
|
PROVOLATILE_VOLATILE,
|
2015-09-16 21:38:47 +02:00
|
|
|
PROPARALLEL_UNSAFE,
|
Change many routines to return ObjectAddress rather than OID
The changed routines are mostly those that can be directly called by
ProcessUtilitySlow; the intention is to make the affected object
information more precise, in support for future event trigger changes.
Originally it was envisioned that the OID of the affected object would
be enough, and in most cases that is correct, but upon actually
implementing the event trigger changes it turned out that ObjectAddress
is more widely useful.
Additionally, some command execution routines grew an output argument
that's an object address which provides further info about the executed
command. To wit:
* for ALTER DOMAIN / ADD CONSTRAINT, it corresponds to the address of
the new constraint
* for ALTER OBJECT / SET SCHEMA, it corresponds to the address of the
schema that originally contained the object.
* for ALTER EXTENSION {ADD, DROP} OBJECT, it corresponds to the address
of the object added to or dropped from the extension.
There's no user-visible change in this commit, and no functional change
either.
Discussion: 20150218213255.GC6717@tamriel.snowman.net
Reviewed-By: Stephen Frost, Andres Freund
2015-03-03 18:10:50 +01:00
|
|
|
buildoidvector(funcargtypes, 1),
|
|
|
|
PointerGetDatum(NULL),
|
|
|
|
PointerGetDatum(NULL),
|
|
|
|
PointerGetDatum(NULL),
|
|
|
|
NIL,
|
|
|
|
PointerGetDatum(NULL),
|
2015-04-26 16:33:14 +02:00
|
|
|
PointerGetDatum(NULL),
|
Change many routines to return ObjectAddress rather than OID
The changed routines are mostly those that can be directly called by
ProcessUtilitySlow; the intention is to make the affected object
information more precise, in support for future event trigger changes.
Originally it was envisioned that the OID of the affected object would
be enough, and in most cases that is correct, but upon actually
implementing the event trigger changes it turned out that ObjectAddress
is more widely useful.
Additionally, some command execution routines grew an output argument
that's an object address which provides further info about the executed
command. To wit:
* for ALTER DOMAIN / ADD CONSTRAINT, it corresponds to the address of
the new constraint
* for ALTER OBJECT / SET SCHEMA, it corresponds to the address of the
schema that originally contained the object.
* for ALTER EXTENSION {ADD, DROP} OBJECT, it corresponds to the address
of the object added to or dropped from the extension.
There's no user-visible change in this commit, and no functional change
either.
Discussion: 20150218213255.GC6717@tamriel.snowman.net
Reviewed-By: Stephen Frost, Andres Freund
2015-03-03 18:10:50 +01:00
|
|
|
1,
|
|
|
|
0);
|
|
|
|
inlineOid = tmpAddr.objectId;
|
2009-09-23 01:43:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
inlineOid = InvalidOid;
|
|
|
|
|
2005-09-06 01:50:49 +02:00
|
|
|
/*
|
|
|
|
* Likewise for the validator, if required; but we don't care about
|
|
|
|
* its return type.
|
|
|
|
*/
|
2005-09-08 22:07:42 +02:00
|
|
|
if (pltemplate->tmplvalidator)
|
2005-09-06 01:50:49 +02:00
|
|
|
{
|
2005-09-08 22:07:42 +02:00
|
|
|
funcname = SystemFuncName(pltemplate->tmplvalidator);
|
2005-09-06 01:50:49 +02:00
|
|
|
funcargtypes[0] = OIDOID;
|
|
|
|
valOid = LookupFuncName(funcname, 1, funcargtypes, true);
|
|
|
|
if (!OidIsValid(valOid))
|
|
|
|
{
|
Change many routines to return ObjectAddress rather than OID
The changed routines are mostly those that can be directly called by
ProcessUtilitySlow; the intention is to make the affected object
information more precise, in support for future event trigger changes.
Originally it was envisioned that the OID of the affected object would
be enough, and in most cases that is correct, but upon actually
implementing the event trigger changes it turned out that ObjectAddress
is more widely useful.
Additionally, some command execution routines grew an output argument
that's an object address which provides further info about the executed
command. To wit:
* for ALTER DOMAIN / ADD CONSTRAINT, it corresponds to the address of
the new constraint
* for ALTER OBJECT / SET SCHEMA, it corresponds to the address of the
schema that originally contained the object.
* for ALTER EXTENSION {ADD, DROP} OBJECT, it corresponds to the address
of the object added to or dropped from the extension.
There's no user-visible change in this commit, and no functional change
either.
Discussion: 20150218213255.GC6717@tamriel.snowman.net
Reviewed-By: Stephen Frost, Andres Freund
2015-03-03 18:10:50 +01:00
|
|
|
tmpAddr = ProcedureCreate(pltemplate->tmplvalidator,
|
|
|
|
PG_CATALOG_NAMESPACE,
|
Phase 2 of pgindent updates.
Change pg_bsd_indent to follow upstream rules for placement of comments
to the right of code, and remove pgindent hack that caused comments
following #endif to not obey the general rule.
Commit e3860ffa4dd0dad0dd9eea4be9cc1412373a8c89 wasn't actually using
the published version of pg_bsd_indent, but a hacked-up version that
tried to minimize the amount of movement of comments to the right of
code. The situation of interest is where such a comment has to be
moved to the right of its default placement at column 33 because there's
code there. BSD indent has always moved right in units of tab stops
in such cases --- but in the previous incarnation, indent was working
in 8-space tab stops, while now it knows we use 4-space tabs. So the
net result is that in about half the cases, such comments are placed
one tab stop left of before. This is better all around: it leaves
more room on the line for comment text, and it means that in such
cases the comment uniformly starts at the next 4-space tab stop after
the code, rather than sometimes one and sometimes two tabs after.
Also, ensure that comments following #endif are indented the same
as comments following other preprocessor commands such as #else.
That inconsistency turns out to have been self-inflicted damage
from a poorly-thought-through post-indent "fixup" in pgindent.
This patch is much less interesting than the first round of indent
changes, but also bulkier, so I thought it best to separate the effects.
Discussion: https://postgr.es/m/E1dAmxK-0006EE-1r@gemulon.postgresql.org
Discussion: https://postgr.es/m/30527.1495162840@sss.pgh.pa.us
2017-06-21 21:18:54 +02:00
|
|
|
false, /* replace */
|
|
|
|
false, /* returnsSet */
|
Change many routines to return ObjectAddress rather than OID
The changed routines are mostly those that can be directly called by
ProcessUtilitySlow; the intention is to make the affected object
information more precise, in support for future event trigger changes.
Originally it was envisioned that the OID of the affected object would
be enough, and in most cases that is correct, but upon actually
implementing the event trigger changes it turned out that ObjectAddress
is more widely useful.
Additionally, some command execution routines grew an output argument
that's an object address which provides further info about the executed
command. To wit:
* for ALTER DOMAIN / ADD CONSTRAINT, it corresponds to the address of
the new constraint
* for ALTER OBJECT / SET SCHEMA, it corresponds to the address of the
schema that originally contained the object.
* for ALTER EXTENSION {ADD, DROP} OBJECT, it corresponds to the address
of the object added to or dropped from the extension.
There's no user-visible change in this commit, and no functional change
either.
Discussion: 20150218213255.GC6717@tamriel.snowman.net
Reviewed-By: Stephen Frost, Andres Freund
2015-03-03 18:10:50 +01:00
|
|
|
VOIDOID,
|
|
|
|
BOOTSTRAP_SUPERUSERID,
|
|
|
|
ClanguageId,
|
|
|
|
F_FMGR_C_VALIDATOR,
|
|
|
|
pltemplate->tmplvalidator,
|
|
|
|
pltemplate->tmpllibrary,
|
Phase 2 of pgindent updates.
Change pg_bsd_indent to follow upstream rules for placement of comments
to the right of code, and remove pgindent hack that caused comments
following #endif to not obey the general rule.
Commit e3860ffa4dd0dad0dd9eea4be9cc1412373a8c89 wasn't actually using
the published version of pg_bsd_indent, but a hacked-up version that
tried to minimize the amount of movement of comments to the right of
code. The situation of interest is where such a comment has to be
moved to the right of its default placement at column 33 because there's
code there. BSD indent has always moved right in units of tab stops
in such cases --- but in the previous incarnation, indent was working
in 8-space tab stops, while now it knows we use 4-space tabs. So the
net result is that in about half the cases, such comments are placed
one tab stop left of before. This is better all around: it leaves
more room on the line for comment text, and it means that in such
cases the comment uniformly starts at the next 4-space tab stop after
the code, rather than sometimes one and sometimes two tabs after.
Also, ensure that comments following #endif are indented the same
as comments following other preprocessor commands such as #else.
That inconsistency turns out to have been self-inflicted damage
from a poorly-thought-through post-indent "fixup" in pgindent.
This patch is much less interesting than the first round of indent
changes, but also bulkier, so I thought it best to separate the effects.
Discussion: https://postgr.es/m/E1dAmxK-0006EE-1r@gemulon.postgresql.org
Discussion: https://postgr.es/m/30527.1495162840@sss.pgh.pa.us
2017-06-21 21:18:54 +02:00
|
|
|
false, /* isAgg */
|
|
|
|
false, /* isWindowFunc */
|
|
|
|
false, /* security_definer */
|
|
|
|
false, /* isLeakProof */
|
Change many routines to return ObjectAddress rather than OID
The changed routines are mostly those that can be directly called by
ProcessUtilitySlow; the intention is to make the affected object
information more precise, in support for future event trigger changes.
Originally it was envisioned that the OID of the affected object would
be enough, and in most cases that is correct, but upon actually
implementing the event trigger changes it turned out that ObjectAddress
is more widely useful.
Additionally, some command execution routines grew an output argument
that's an object address which provides further info about the executed
command. To wit:
* for ALTER DOMAIN / ADD CONSTRAINT, it corresponds to the address of
the new constraint
* for ALTER OBJECT / SET SCHEMA, it corresponds to the address of the
schema that originally contained the object.
* for ALTER EXTENSION {ADD, DROP} OBJECT, it corresponds to the address
of the object added to or dropped from the extension.
There's no user-visible change in this commit, and no functional change
either.
Discussion: 20150218213255.GC6717@tamriel.snowman.net
Reviewed-By: Stephen Frost, Andres Freund
2015-03-03 18:10:50 +01:00
|
|
|
true, /* isStrict */
|
|
|
|
PROVOLATILE_VOLATILE,
|
2015-09-16 21:38:47 +02:00
|
|
|
PROPARALLEL_UNSAFE,
|
Change many routines to return ObjectAddress rather than OID
The changed routines are mostly those that can be directly called by
ProcessUtilitySlow; the intention is to make the affected object
information more precise, in support for future event trigger changes.
Originally it was envisioned that the OID of the affected object would
be enough, and in most cases that is correct, but upon actually
implementing the event trigger changes it turned out that ObjectAddress
is more widely useful.
Additionally, some command execution routines grew an output argument
that's an object address which provides further info about the executed
command. To wit:
* for ALTER DOMAIN / ADD CONSTRAINT, it corresponds to the address of
the new constraint
* for ALTER OBJECT / SET SCHEMA, it corresponds to the address of the
schema that originally contained the object.
* for ALTER EXTENSION {ADD, DROP} OBJECT, it corresponds to the address
of the object added to or dropped from the extension.
There's no user-visible change in this commit, and no functional change
either.
Discussion: 20150218213255.GC6717@tamriel.snowman.net
Reviewed-By: Stephen Frost, Andres Freund
2015-03-03 18:10:50 +01:00
|
|
|
buildoidvector(funcargtypes, 1),
|
|
|
|
PointerGetDatum(NULL),
|
|
|
|
PointerGetDatum(NULL),
|
|
|
|
PointerGetDatum(NULL),
|
|
|
|
NIL,
|
|
|
|
PointerGetDatum(NULL),
|
2015-04-26 16:33:14 +02:00
|
|
|
PointerGetDatum(NULL),
|
Change many routines to return ObjectAddress rather than OID
The changed routines are mostly those that can be directly called by
ProcessUtilitySlow; the intention is to make the affected object
information more precise, in support for future event trigger changes.
Originally it was envisioned that the OID of the affected object would
be enough, and in most cases that is correct, but upon actually
implementing the event trigger changes it turned out that ObjectAddress
is more widely useful.
Additionally, some command execution routines grew an output argument
that's an object address which provides further info about the executed
command. To wit:
* for ALTER DOMAIN / ADD CONSTRAINT, it corresponds to the address of
the new constraint
* for ALTER OBJECT / SET SCHEMA, it corresponds to the address of the
schema that originally contained the object.
* for ALTER EXTENSION {ADD, DROP} OBJECT, it corresponds to the address
of the object added to or dropped from the extension.
There's no user-visible change in this commit, and no functional change
either.
Discussion: 20150218213255.GC6717@tamriel.snowman.net
Reviewed-By: Stephen Frost, Andres Freund
2015-03-03 18:10:50 +01:00
|
|
|
1,
|
|
|
|
0);
|
|
|
|
valOid = tmpAddr.objectId;
|
2005-09-06 01:50:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
valOid = InvalidOid;
|
|
|
|
|
|
|
|
/* ok, create it */
|
2012-12-29 13:55:37 +01:00
|
|
|
return create_proc_lang(stmt->plname, stmt->replace, GetUserId(),
|
|
|
|
handlerOid, inlineOid,
|
|
|
|
valOid, pltemplate->tmpltrusted);
|
2002-05-22 19:21:02 +02:00
|
|
|
}
|
|
|
|
else
|
2005-09-06 01:50:49 +02:00
|
|
|
{
|
|
|
|
/*
|
2005-10-15 04:49:52 +02:00
|
|
|
* No template, so use the provided information. If there's no
|
|
|
|
* handler clause, the user is trying to rely on a template that we
|
|
|
|
* don't have, so complain accordingly.
|
2005-09-06 01:50:49 +02:00
|
|
|
*/
|
|
|
|
if (!stmt->plhandler)
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
|
|
|
errmsg("unsupported language \"%s\"",
|
2011-11-17 20:20:13 +01:00
|
|
|
stmt->plname),
|
2005-09-08 22:07:42 +02:00
|
|
|
errhint("The supported languages are listed in the pg_pltemplate system catalog.")));
|
2005-09-06 01:50:49 +02:00
|
|
|
|
2007-03-26 18:58:41 +02:00
|
|
|
/*
|
|
|
|
* Check permission
|
|
|
|
*/
|
|
|
|
if (!superuser())
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
|
|
|
|
errmsg("must be superuser to create custom procedural language")));
|
|
|
|
|
2005-09-06 01:50:49 +02:00
|
|
|
/*
|
|
|
|
* Lookup the PL handler function and check that it is of the expected
|
|
|
|
* return type
|
|
|
|
*/
|
|
|
|
handlerOid = LookupFuncName(stmt->plhandler, 0, funcargtypes, false);
|
|
|
|
funcrettype = get_func_rettype(handlerOid);
|
|
|
|
if (funcrettype != LANGUAGE_HANDLEROID)
|
|
|
|
{
|
|
|
|
/*
|
2014-05-06 18:12:18 +02:00
|
|
|
* We allow OPAQUE just so we can load old dump files. When we
|
2005-09-06 01:50:49 +02:00
|
|
|
* see a handler function declared OPAQUE, change it to
|
|
|
|
* LANGUAGE_HANDLER. (This is probably obsolete and removable?)
|
|
|
|
*/
|
|
|
|
if (funcrettype == OPAQUEOID)
|
|
|
|
{
|
|
|
|
ereport(WARNING,
|
|
|
|
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
|
Phase 3 of pgindent updates.
Don't move parenthesized lines to the left, even if that means they
flow past the right margin.
By default, BSD indent lines up statement continuation lines that are
within parentheses so that they start just to the right of the preceding
left parenthesis. However, traditionally, if that resulted in the
continuation line extending to the right of the desired right margin,
then indent would push it left just far enough to not overrun the margin,
if it could do so without making the continuation line start to the left of
the current statement indent. That makes for a weird mix of indentations
unless one has been completely rigid about never violating the 80-column
limit.
This behavior has been pretty universally panned by Postgres developers.
Hence, disable it with indent's new -lpl switch, so that parenthesized
lines are always lined up with the preceding left paren.
This patch is much less interesting than the first round of indent
changes, but also bulkier, so I thought it best to separate the effects.
Discussion: https://postgr.es/m/E1dAmxK-0006EE-1r@gemulon.postgresql.org
Discussion: https://postgr.es/m/30527.1495162840@sss.pgh.pa.us
2017-06-21 21:35:54 +02:00
|
|
|
errmsg("changing return type of function %s from %s to %s",
|
|
|
|
NameListToString(stmt->plhandler),
|
|
|
|
"opaque", "language_handler")));
|
2005-09-06 01:50:49 +02:00
|
|
|
SetFunctionReturnType(handlerOid, LANGUAGE_HANDLEROID);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
|
2016-06-10 00:02:36 +02:00
|
|
|
errmsg("function %s must return type %s",
|
Phase 3 of pgindent updates.
Don't move parenthesized lines to the left, even if that means they
flow past the right margin.
By default, BSD indent lines up statement continuation lines that are
within parentheses so that they start just to the right of the preceding
left parenthesis. However, traditionally, if that resulted in the
continuation line extending to the right of the desired right margin,
then indent would push it left just far enough to not overrun the margin,
if it could do so without making the continuation line start to the left of
the current statement indent. That makes for a weird mix of indentations
unless one has been completely rigid about never violating the 80-column
limit.
This behavior has been pretty universally panned by Postgres developers.
Hence, disable it with indent's new -lpl switch, so that parenthesized
lines are always lined up with the preceding left paren.
This patch is much less interesting than the first round of indent
changes, but also bulkier, so I thought it best to separate the effects.
Discussion: https://postgr.es/m/E1dAmxK-0006EE-1r@gemulon.postgresql.org
Discussion: https://postgr.es/m/30527.1495162840@sss.pgh.pa.us
2017-06-21 21:35:54 +02:00
|
|
|
NameListToString(stmt->plhandler), "language_handler")));
|
2005-09-06 01:50:49 +02:00
|
|
|
}
|
|
|
|
|
2009-09-23 01:43:43 +02:00
|
|
|
/* validate the inline function */
|
|
|
|
if (stmt->plinline)
|
|
|
|
{
|
|
|
|
funcargtypes[0] = INTERNALOID;
|
|
|
|
inlineOid = LookupFuncName(stmt->plinline, 1, funcargtypes, false);
|
|
|
|
/* return value is ignored, so we don't check the type */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
inlineOid = InvalidOid;
|
|
|
|
|
2005-09-06 01:50:49 +02:00
|
|
|
/* validate the validator function */
|
|
|
|
if (stmt->plvalidator)
|
|
|
|
{
|
|
|
|
funcargtypes[0] = OIDOID;
|
|
|
|
valOid = LookupFuncName(stmt->plvalidator, 1, funcargtypes, false);
|
|
|
|
/* return value is ignored, so we don't check the type */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
valOid = InvalidOid;
|
|
|
|
|
|
|
|
/* ok, create it */
|
2012-12-29 13:55:37 +01:00
|
|
|
return create_proc_lang(stmt->plname, stmt->replace, GetUserId(),
|
|
|
|
handlerOid, inlineOid,
|
|
|
|
valOid, stmt->pltrusted);
|
2005-09-06 01:50:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Guts of language creation.
|
|
|
|
*/
|
Change many routines to return ObjectAddress rather than OID
The changed routines are mostly those that can be directly called by
ProcessUtilitySlow; the intention is to make the affected object
information more precise, in support for future event trigger changes.
Originally it was envisioned that the OID of the affected object would
be enough, and in most cases that is correct, but upon actually
implementing the event trigger changes it turned out that ObjectAddress
is more widely useful.
Additionally, some command execution routines grew an output argument
that's an object address which provides further info about the executed
command. To wit:
* for ALTER DOMAIN / ADD CONSTRAINT, it corresponds to the address of
the new constraint
* for ALTER OBJECT / SET SCHEMA, it corresponds to the address of the
schema that originally contained the object.
* for ALTER EXTENSION {ADD, DROP} OBJECT, it corresponds to the address
of the object added to or dropped from the extension.
There's no user-visible change in this commit, and no functional change
either.
Discussion: 20150218213255.GC6717@tamriel.snowman.net
Reviewed-By: Stephen Frost, Andres Freund
2015-03-03 18:10:50 +01:00
|
|
|
static ObjectAddress
|
2010-02-23 23:51:43 +01:00
|
|
|
create_proc_lang(const char *languageName, bool replace,
|
2009-09-23 01:43:43 +02:00
|
|
|
Oid languageOwner, Oid handlerOid, Oid inlineOid,
|
|
|
|
Oid valOid, bool trusted)
|
2005-09-06 01:50:49 +02:00
|
|
|
{
|
|
|
|
Relation rel;
|
|
|
|
TupleDesc tupDesc;
|
|
|
|
Datum values[Natts_pg_language];
|
2008-11-02 02:45:28 +01:00
|
|
|
bool nulls[Natts_pg_language];
|
2010-02-23 23:51:43 +01:00
|
|
|
bool replaces[Natts_pg_language];
|
2005-09-06 01:50:49 +02:00
|
|
|
NameData langname;
|
2010-02-23 23:51:43 +01:00
|
|
|
HeapTuple oldtup;
|
2005-09-06 01:50:49 +02:00
|
|
|
HeapTuple tup;
|
2010-02-23 23:51:43 +01:00
|
|
|
bool is_update;
|
2005-09-06 01:50:49 +02:00
|
|
|
ObjectAddress myself,
|
|
|
|
referenced;
|
2002-05-22 19:21:02 +02:00
|
|
|
|
2005-09-06 01:50:49 +02:00
|
|
|
rel = heap_open(LanguageRelationId, RowExclusiveLock);
|
2010-02-23 23:51:43 +01:00
|
|
|
tupDesc = RelationGetDescr(rel);
|
1997-10-28 16:11:45 +01:00
|
|
|
|
2010-02-23 23:51:43 +01:00
|
|
|
/* Prepare data to be inserted */
|
2005-09-06 01:50:49 +02:00
|
|
|
memset(values, 0, sizeof(values));
|
2008-11-02 02:45:28 +01:00
|
|
|
memset(nulls, false, sizeof(nulls));
|
2010-02-23 23:51:43 +01:00
|
|
|
memset(replaces, true, sizeof(replaces));
|
1997-10-28 16:11:45 +01:00
|
|
|
|
2005-09-06 01:50:49 +02:00
|
|
|
namestrcpy(&langname, languageName);
|
|
|
|
values[Anum_pg_language_lanname - 1] = NameGetDatum(&langname);
|
2007-03-26 18:58:41 +02:00
|
|
|
values[Anum_pg_language_lanowner - 1] = ObjectIdGetDatum(languageOwner);
|
2005-09-06 01:50:49 +02:00
|
|
|
values[Anum_pg_language_lanispl - 1] = BoolGetDatum(true);
|
|
|
|
values[Anum_pg_language_lanpltrusted - 1] = BoolGetDatum(trusted);
|
|
|
|
values[Anum_pg_language_lanplcallfoid - 1] = ObjectIdGetDatum(handlerOid);
|
2009-09-23 01:43:43 +02:00
|
|
|
values[Anum_pg_language_laninline - 1] = ObjectIdGetDatum(inlineOid);
|
2005-09-06 01:50:49 +02:00
|
|
|
values[Anum_pg_language_lanvalidator - 1] = ObjectIdGetDatum(valOid);
|
2008-11-02 02:45:28 +01:00
|
|
|
nulls[Anum_pg_language_lanacl - 1] = true;
|
1997-10-28 16:11:45 +01:00
|
|
|
|
2010-02-23 23:51:43 +01:00
|
|
|
/* Check for pre-existing definition */
|
|
|
|
oldtup = SearchSysCache1(LANGNAME, PointerGetDatum(languageName));
|
|
|
|
|
|
|
|
if (HeapTupleIsValid(oldtup))
|
|
|
|
{
|
|
|
|
/* There is one; okay to replace it? */
|
|
|
|
if (!replace)
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_DUPLICATE_OBJECT),
|
|
|
|
errmsg("language \"%s\" already exists", languageName)));
|
|
|
|
if (!pg_language_ownercheck(HeapTupleGetOid(oldtup), languageOwner))
|
2017-12-02 15:26:34 +01:00
|
|
|
aclcheck_error(ACLCHECK_NOT_OWNER, OBJECT_LANGUAGE,
|
2010-02-23 23:51:43 +01:00
|
|
|
languageName);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do not change existing ownership or permissions. Note
|
|
|
|
* dependency-update code below has to agree with this decision.
|
|
|
|
*/
|
|
|
|
replaces[Anum_pg_language_lanowner - 1] = false;
|
|
|
|
replaces[Anum_pg_language_lanacl - 1] = false;
|
|
|
|
|
|
|
|
/* Okay, do it... */
|
|
|
|
tup = heap_modify_tuple(oldtup, tupDesc, values, nulls, replaces);
|
2017-01-31 22:42:24 +01:00
|
|
|
CatalogTupleUpdate(rel, &tup->t_self, tup);
|
1997-10-28 16:11:45 +01:00
|
|
|
|
2010-02-23 23:51:43 +01:00
|
|
|
ReleaseSysCache(oldtup);
|
|
|
|
is_update = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Creating a new language */
|
|
|
|
tup = heap_form_tuple(tupDesc, values, nulls);
|
2017-01-31 22:42:24 +01:00
|
|
|
CatalogTupleInsert(rel, tup);
|
2010-02-23 23:51:43 +01:00
|
|
|
is_update = false;
|
|
|
|
}
|
1997-10-28 16:11:45 +01:00
|
|
|
|
2002-07-17 00:12:20 +02:00
|
|
|
/*
|
2010-02-23 23:51:43 +01:00
|
|
|
* Create dependencies for the new language. If we are updating an
|
|
|
|
* existing language, first delete any existing pg_depend entries.
|
|
|
|
* (However, since we are not changing ownership or permissions, the
|
2011-07-23 22:59:39 +02:00
|
|
|
* shared dependencies do *not* need to change, and we leave them alone.)
|
2002-07-17 00:12:20 +02:00
|
|
|
*/
|
2005-04-14 22:03:27 +02:00
|
|
|
myself.classId = LanguageRelationId;
|
2002-07-20 07:16:59 +02:00
|
|
|
myself.objectId = HeapTupleGetOid(tup);
|
2002-07-17 00:12:20 +02:00
|
|
|
myself.objectSubId = 0;
|
|
|
|
|
2010-02-23 23:51:43 +01:00
|
|
|
if (is_update)
|
2011-02-08 22:08:41 +01:00
|
|
|
deleteDependencyRecordsFor(myself.classId, myself.objectId, true);
|
2010-02-23 23:51:43 +01:00
|
|
|
|
2007-03-26 18:58:41 +02:00
|
|
|
/* dependency on owner of language */
|
2010-02-23 23:51:43 +01:00
|
|
|
if (!is_update)
|
|
|
|
recordDependencyOnOwner(myself.classId, myself.objectId,
|
|
|
|
languageOwner);
|
2007-03-26 18:58:41 +02:00
|
|
|
|
2011-02-08 22:08:41 +01:00
|
|
|
/* dependency on extension */
|
2011-07-23 22:59:39 +02:00
|
|
|
recordDependencyOnCurrentExtension(&myself, is_update);
|
2011-02-08 22:08:41 +01:00
|
|
|
|
2002-07-17 00:12:20 +02:00
|
|
|
/* dependency on the PL handler function */
|
2005-04-14 03:38:22 +02:00
|
|
|
referenced.classId = ProcedureRelationId;
|
2005-09-06 01:50:49 +02:00
|
|
|
referenced.objectId = handlerOid;
|
2002-07-17 00:12:20 +02:00
|
|
|
referenced.objectSubId = 0;
|
|
|
|
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
|
|
|
|
|
2009-09-23 01:43:43 +02:00
|
|
|
/* dependency on the inline handler function, if any */
|
|
|
|
if (OidIsValid(inlineOid))
|
|
|
|
{
|
|
|
|
referenced.classId = ProcedureRelationId;
|
|
|
|
referenced.objectId = inlineOid;
|
|
|
|
referenced.objectSubId = 0;
|
|
|
|
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
|
|
|
|
}
|
|
|
|
|
2002-07-17 00:12:20 +02:00
|
|
|
/* dependency on the validator function, if any */
|
2005-09-06 01:50:49 +02:00
|
|
|
if (OidIsValid(valOid))
|
2002-07-17 00:12:20 +02:00
|
|
|
{
|
2005-04-14 03:38:22 +02:00
|
|
|
referenced.classId = ProcedureRelationId;
|
2005-09-06 01:50:49 +02:00
|
|
|
referenced.objectId = valOid;
|
2002-07-17 00:12:20 +02:00
|
|
|
referenced.objectSubId = 0;
|
|
|
|
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
|
|
|
|
}
|
|
|
|
|
2010-11-25 17:48:49 +01:00
|
|
|
/* Post creation hook for new procedural language */
|
2013-03-07 02:52:06 +01:00
|
|
|
InvokeObjectPostCreateHook(LanguageRelationId, myself.objectId, 0);
|
2010-11-25 17:48:49 +01:00
|
|
|
|
1999-09-18 21:08:25 +02:00
|
|
|
heap_close(rel, RowExclusiveLock);
|
2012-12-29 13:55:37 +01:00
|
|
|
|
Change many routines to return ObjectAddress rather than OID
The changed routines are mostly those that can be directly called by
ProcessUtilitySlow; the intention is to make the affected object
information more precise, in support for future event trigger changes.
Originally it was envisioned that the OID of the affected object would
be enough, and in most cases that is correct, but upon actually
implementing the event trigger changes it turned out that ObjectAddress
is more widely useful.
Additionally, some command execution routines grew an output argument
that's an object address which provides further info about the executed
command. To wit:
* for ALTER DOMAIN / ADD CONSTRAINT, it corresponds to the address of
the new constraint
* for ALTER OBJECT / SET SCHEMA, it corresponds to the address of the
schema that originally contained the object.
* for ALTER EXTENSION {ADD, DROP} OBJECT, it corresponds to the address
of the object added to or dropped from the extension.
There's no user-visible change in this commit, and no functional change
either.
Discussion: 20150218213255.GC6717@tamriel.snowman.net
Reviewed-By: Stephen Frost, Andres Freund
2015-03-03 18:10:50 +01:00
|
|
|
return myself;
|
1997-10-28 16:11:45 +01:00
|
|
|
}
|
|
|
|
|
2005-09-06 01:50:49 +02:00
|
|
|
/*
|
|
|
|
* Look to see if we have template information for the given language name.
|
|
|
|
*/
|
|
|
|
static PLTemplate *
|
|
|
|
find_language_template(const char *languageName)
|
|
|
|
{
|
2005-09-08 22:07:42 +02:00
|
|
|
PLTemplate *result;
|
|
|
|
Relation rel;
|
|
|
|
SysScanDesc scan;
|
|
|
|
ScanKeyData key;
|
|
|
|
HeapTuple tup;
|
|
|
|
|
|
|
|
rel = heap_open(PLTemplateRelationId, AccessShareLock);
|
|
|
|
|
|
|
|
ScanKeyInit(&key,
|
|
|
|
Anum_pg_pltemplate_tmplname,
|
|
|
|
BTEqualStrategyNumber, F_NAMEEQ,
|
2016-09-13 23:17:48 +02:00
|
|
|
CStringGetDatum(languageName));
|
2005-09-08 22:07:42 +02:00
|
|
|
scan = systable_beginscan(rel, PLTemplateNameIndexId, true,
|
Use an MVCC snapshot, rather than SnapshotNow, for catalog scans.
SnapshotNow scans have the undesirable property that, in the face of
concurrent updates, the scan can fail to see either the old or the new
versions of the row. In many cases, we work around this by requiring
DDL operations to hold AccessExclusiveLock on the object being
modified; in some cases, the existing locking is inadequate and random
failures occur as a result. This commit doesn't change anything
related to locking, but will hopefully pave the way to allowing lock
strength reductions in the future.
The major issue has held us back from making this change in the past
is that taking an MVCC snapshot is significantly more expensive than
using a static special snapshot such as SnapshotNow. However, testing
of various worst-case scenarios reveals that this problem is not
severe except under fairly extreme workloads. To mitigate those
problems, we avoid retaking the MVCC snapshot for each new scan;
instead, we take a new snapshot only when invalidation messages have
been processed. The catcache machinery already requires that
invalidation messages be sent before releasing the related heavyweight
lock; else other backends might rely on locally-cached data rather
than scanning the catalog at all. Thus, making snapshot reuse
dependent on the same guarantees shouldn't break anything that wasn't
already subtly broken.
Patch by me. Review by Michael Paquier and Andres Freund.
2013-07-02 15:47:01 +02:00
|
|
|
NULL, 1, &key);
|
2005-09-08 22:07:42 +02:00
|
|
|
|
|
|
|
tup = systable_getnext(scan);
|
|
|
|
if (HeapTupleIsValid(tup))
|
2005-09-06 01:50:49 +02:00
|
|
|
{
|
2005-09-08 22:07:42 +02:00
|
|
|
Form_pg_pltemplate tmpl = (Form_pg_pltemplate) GETSTRUCT(tup);
|
|
|
|
Datum datum;
|
|
|
|
bool isnull;
|
|
|
|
|
|
|
|
result = (PLTemplate *) palloc0(sizeof(PLTemplate));
|
|
|
|
result->tmpltrusted = tmpl->tmpltrusted;
|
2007-03-26 18:58:41 +02:00
|
|
|
result->tmpldbacreate = tmpl->tmpldbacreate;
|
2005-09-08 22:07:42 +02:00
|
|
|
|
|
|
|
/* Remaining fields are variable-width so we need heap_getattr */
|
|
|
|
datum = heap_getattr(tup, Anum_pg_pltemplate_tmplhandler,
|
|
|
|
RelationGetDescr(rel), &isnull);
|
|
|
|
if (!isnull)
|
2008-03-25 23:42:46 +01:00
|
|
|
result->tmplhandler = TextDatumGetCString(datum);
|
2005-09-08 22:07:42 +02:00
|
|
|
|
2009-09-23 01:43:43 +02:00
|
|
|
datum = heap_getattr(tup, Anum_pg_pltemplate_tmplinline,
|
|
|
|
RelationGetDescr(rel), &isnull);
|
|
|
|
if (!isnull)
|
|
|
|
result->tmplinline = TextDatumGetCString(datum);
|
|
|
|
|
2005-09-08 22:07:42 +02:00
|
|
|
datum = heap_getattr(tup, Anum_pg_pltemplate_tmplvalidator,
|
|
|
|
RelationGetDescr(rel), &isnull);
|
|
|
|
if (!isnull)
|
2008-03-25 23:42:46 +01:00
|
|
|
result->tmplvalidator = TextDatumGetCString(datum);
|
2005-09-08 22:07:42 +02:00
|
|
|
|
|
|
|
datum = heap_getattr(tup, Anum_pg_pltemplate_tmpllibrary,
|
|
|
|
RelationGetDescr(rel), &isnull);
|
|
|
|
if (!isnull)
|
2008-03-25 23:42:46 +01:00
|
|
|
result->tmpllibrary = TextDatumGetCString(datum);
|
2005-09-08 22:07:42 +02:00
|
|
|
|
|
|
|
/* Ignore template if handler or library info is missing */
|
|
|
|
if (!result->tmplhandler || !result->tmpllibrary)
|
|
|
|
result = NULL;
|
2005-09-06 01:50:49 +02:00
|
|
|
}
|
2005-09-08 22:07:42 +02:00
|
|
|
else
|
|
|
|
result = NULL;
|
|
|
|
|
|
|
|
systable_endscan(scan);
|
|
|
|
|
|
|
|
heap_close(rel, AccessShareLock);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2017-08-16 06:22:32 +02:00
|
|
|
* This just returns true if we have a valid template for a given language
|
2005-09-08 22:07:42 +02:00
|
|
|
*/
|
|
|
|
bool
|
|
|
|
PLTemplateExists(const char *languageName)
|
|
|
|
{
|
|
|
|
return (find_language_template(languageName) != NULL);
|
2005-09-06 01:50:49 +02:00
|
|
|
}
|
|
|
|
|
2002-07-12 20:43:19 +02:00
|
|
|
/*
|
|
|
|
* Guts of language dropping.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
DropProceduralLanguageById(Oid langOid)
|
|
|
|
{
|
|
|
|
Relation rel;
|
|
|
|
HeapTuple langTup;
|
|
|
|
|
2005-04-14 22:03:27 +02:00
|
|
|
rel = heap_open(LanguageRelationId, RowExclusiveLock);
|
2002-07-12 20:43:19 +02:00
|
|
|
|
2010-02-14 19:42:19 +01:00
|
|
|
langTup = SearchSysCache1(LANGOID, ObjectIdGetDatum(langOid));
|
Phase 2 of pgindent updates.
Change pg_bsd_indent to follow upstream rules for placement of comments
to the right of code, and remove pgindent hack that caused comments
following #endif to not obey the general rule.
Commit e3860ffa4dd0dad0dd9eea4be9cc1412373a8c89 wasn't actually using
the published version of pg_bsd_indent, but a hacked-up version that
tried to minimize the amount of movement of comments to the right of
code. The situation of interest is where such a comment has to be
moved to the right of its default placement at column 33 because there's
code there. BSD indent has always moved right in units of tab stops
in such cases --- but in the previous incarnation, indent was working
in 8-space tab stops, while now it knows we use 4-space tabs. So the
net result is that in about half the cases, such comments are placed
one tab stop left of before. This is better all around: it leaves
more room on the line for comment text, and it means that in such
cases the comment uniformly starts at the next 4-space tab stop after
the code, rather than sometimes one and sometimes two tabs after.
Also, ensure that comments following #endif are indented the same
as comments following other preprocessor commands such as #else.
That inconsistency turns out to have been self-inflicted damage
from a poorly-thought-through post-indent "fixup" in pgindent.
This patch is much less interesting than the first round of indent
changes, but also bulkier, so I thought it best to separate the effects.
Discussion: https://postgr.es/m/E1dAmxK-0006EE-1r@gemulon.postgresql.org
Discussion: https://postgr.es/m/30527.1495162840@sss.pgh.pa.us
2017-06-21 21:18:54 +02:00
|
|
|
if (!HeapTupleIsValid(langTup)) /* should not happen */
|
2003-07-19 01:20:33 +02:00
|
|
|
elog(ERROR, "cache lookup failed for language %u", langOid);
|
2002-07-12 20:43:19 +02:00
|
|
|
|
2017-02-01 22:13:30 +01:00
|
|
|
CatalogTupleDelete(rel, &langTup->t_self);
|
1997-10-28 16:11:45 +01:00
|
|
|
|
2002-07-12 20:43:19 +02:00
|
|
|
ReleaseSysCache(langTup);
|
|
|
|
|
1999-09-18 21:08:25 +02:00
|
|
|
heap_close(rel, RowExclusiveLock);
|
1997-10-28 16:11:45 +01:00
|
|
|
}
|
2003-06-27 16:45:32 +02:00
|
|
|
|
2010-08-05 16:45:09 +02:00
|
|
|
/*
|
|
|
|
* get_language_oid - given a language name, look up the OID
|
|
|
|
*
|
|
|
|
* If missing_ok is false, throw an error if language name not found. If
|
|
|
|
* true, just return InvalidOid.
|
|
|
|
*/
|
|
|
|
Oid
|
|
|
|
get_language_oid(const char *langname, bool missing_ok)
|
|
|
|
{
|
|
|
|
Oid oid;
|
|
|
|
|
|
|
|
oid = GetSysCacheOid1(LANGNAME, CStringGetDatum(langname));
|
|
|
|
if (!OidIsValid(oid) && !missing_ok)
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
|
|
|
errmsg("language \"%s\" does not exist", langname)));
|
|
|
|
return oid;
|
|
|
|
}
|