From 11b58470581f1c8cfad670c57ac3ffe77d1f0cdd Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Tue, 23 Feb 2010 22:51:43 +0000 Subject: 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. --- src/backend/parser/gram.y | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'src/backend/parser') diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index 94b28bf3d89..368586a95e6 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -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; } ; -- cgit v1.2.3