1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-22 12:22:45 +03:00

Add CREATE OR REPLACE FUNCTION syntax to allow replacing a function

definition without changing the function's OID, thereby not breaking
rules, views, triggers, etc that depend on it.  From Gavin Sherry.
This commit is contained in:
Tom Lane
2001-10-02 21:39:36 +00:00
parent f24fe14162
commit f2c657375d
12 changed files with 130 additions and 68 deletions

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/keywords.c,v 1.44 2001/09/19 14:09:32 meskes Exp $
* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/keywords.c,v 1.45 2001/10/02 21:39:36 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -118,6 +118,7 @@ static ScanKeyword ScanKeywords[] = {
{"force", FORCE},
{"foreign", FOREIGN},
{"forward", FORWARD},
{"freeze", FREEZE},
{"from", FROM},
{"full", FULL},
{"function", FUNCTION},
@@ -215,6 +216,7 @@ static ScanKeyword ScanKeywords[] = {
{"reindex", REINDEX},
{"relative", RELATIVE},
{"rename", RENAME},
{"replace", REPLACE},
{"reset", RESET},
{"restrict", RESTRICT},
{"returns", RETURNS},
@@ -262,7 +264,7 @@ static ScanKeyword ScanKeywords[] = {
{"truncate", TRUNCATE},
{"trusted", TRUSTED},
{"type", TYPE_P},
{"unencrypted", UNENCRYPTED},
{"unencrypted", UNENCRYPTED},
{"union", UNION},
{"unique", UNIQUE},
{"unknown", UNKNOWN},

View File

@@ -202,7 +202,7 @@ make_name(void)
%token DEFERRABLE, DEFERRED,
IMMEDIATE, INITIALLY,
PENDANT,
RESTRICT,
REPLACE, RESTRICT,
TRIGGER
/* Keywords (in SQL92 non-reserved words) */
@@ -338,7 +338,7 @@ make_name(void)
%type <str> constraints_set_mode comment_type comment_cl comment_ag
%type <str> CreateGroupStmt AlterGroupStmt DropGroupStmt key_delete
%type <str> opt_force key_update CreateSchemaStmt PosIntStringConst
%type <str> IntConst PosIntConst grantee_list func_type
%type <str> IntConst PosIntConst grantee_list func_type opt_or_replace
%type <str> select_limit opt_for_update_clause CheckPointStmt
%type <str> ECPGWhenever ECPGConnect connection_target ECPGOpen
@@ -1881,26 +1881,24 @@ RecipeStmt: EXECUTE RECIPE recipe_name
/*****************************************************************************
*
* QUERY:
* define function <fname>
* [(<type-1> { , <type-n>})]
* returns <type-r>
* as <filename or code in language as appropriate>
* language <lang> [with
* [ arch_pct = <percentage | pre-defined>]
* [, disk_pct = <percentage | pre-defined>]
* [, byte_pct = <percentage | pre-defined>]
* [, perbyte_cpu = <int | pre-defined>]
* [, percall_cpu = <int | pre-defined>]
* [, iscachable]
* create [or replace] function <fname>
* [(<type-1> { , <type-n>})]
* returns <type-r>
* as <filename or code in language as appropriate>
* language <lang> [with parameters]
*
*****************************************************************************/
ProcedureStmt: CREATE FUNCTION func_name func_args
ProcedureStmt: CREATE opt_or_replace FUNCTION func_name func_args
RETURNS func_return AS func_as LANGUAGE ColId_or_Sconst opt_with
{
$$ = cat_str(10, make_str("create function"), $3, $4, make_str("returns"), $6, make_str("as"), $8, make_str("language"), $10, $11);
$$ = cat_str(12, make_str("create"), $2, make_str("function"), $4, $5, make_str("returns"), $7, make_str("as"), $9, make_str("language"), $11, $12);
}
opt_or_replace: OR REPLACE { $$ = make_str("or replace"); }
| /*EMPTY*/ { $$ = EMPTY; }
;
opt_with: WITH definition { $$ = cat2_str(make_str("with"), $2); }
| /*EMPTY*/ { $$ = EMPTY; }
;
@@ -5043,6 +5041,7 @@ TokenId: ABSOLUTE { $$ = make_str("absolute"); }
| REINDEX { $$ = make_str("reindex"); }
| RELATIVE { $$ = make_str("relative"); }
| RENAME { $$ = make_str("rename"); }
| REPLACE { $$ = make_str("replace"); }
| RESTRICT { $$ = make_str("restrict"); }
| RETURNS { $$ = make_str("returns"); }
| REVOKE { $$ = make_str("revoke"); }