1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-09 22:41:56 +03:00

Add an OR REPLACE option to CREATE LANGUAGE.

This operates in the same way as other CREATE OR REPLACE commands, ie,
it replaces everything but the ownership and ACL lists of an existing
entry, and requires the caller to have owner privileges for that entry.

While modifying an existing language has some use in development scenarios,
in typical usage all the "replaced" values come from pg_pltemplate so there
will be no actual change in the language definition.  The reason for adding
this is mainly to allow programs to ensure that a language exists without
triggering an error if it already does exist.

This commit just adds and documents the new option.  A followon patch
will use it to clean up some unpleasant cases in pg_dump and pg_regress.
This commit is contained in:
Tom Lane
2010-02-23 22:51:43 +00:00
parent c4fc082a5a
commit 11b5847058
6 changed files with 102 additions and 46 deletions

View File

@ -11,7 +11,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.710 2010/02/17 04:19:39 tgl Exp $
* $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.711 2010/02/23 22:51:42 tgl Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
@ -2882,16 +2882,17 @@ NumericOnly:
/*****************************************************************************
*
* QUERIES :
* CREATE PROCEDURAL LANGUAGE ...
* DROP PROCEDURAL LANGUAGE ...
* CREATE [OR REPLACE] [TRUSTED] [PROCEDURAL] LANGUAGE ...
* DROP [PROCEDURAL] LANGUAGE ...
*
*****************************************************************************/
CreatePLangStmt:
CREATE opt_trusted opt_procedural LANGUAGE ColId_or_Sconst
CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE ColId_or_Sconst
{
CreatePLangStmt *n = makeNode(CreatePLangStmt);
n->plname = $5;
n->replace = $2;
n->plname = $6;
/* parameters are all to be supplied by system */
n->plhandler = NIL;
n->plinline = NIL;
@ -2899,15 +2900,16 @@ CreatePLangStmt:
n->pltrusted = false;
$$ = (Node *)n;
}
| CREATE opt_trusted opt_procedural LANGUAGE ColId_or_Sconst
| CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE ColId_or_Sconst
HANDLER handler_name opt_inline_handler opt_validator
{
CreatePLangStmt *n = makeNode(CreatePLangStmt);
n->plname = $5;
n->plhandler = $7;
n->plinline = $8;
n->plvalidator = $9;
n->pltrusted = $2;
n->replace = $2;
n->plname = $6;
n->plhandler = $8;
n->plinline = $9;
n->plvalidator = $10;
n->pltrusted = $3;
$$ = (Node *)n;
}
;