diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2008-12-31 02:25:06 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2008-12-31 02:25:06 +0000 |
commit | 26ce4e85a1605326f29e3cb0cc715ddf522a753a (patch) | |
tree | bfd2ca91df26e9aff0873e0c59ce20d3ae096621 /src/backend/commands/functioncmds.c | |
parent | 8e8854daa2b4b3ef9e3fc1a56c79608a70018058 (diff) | |
download | postgresql-26ce4e85a1605326f29e3cb0cc715ddf522a753a.tar.gz postgresql-26ce4e85a1605326f29e3cb0cc715ddf522a753a.zip |
Add a WINDOW attribute to CREATE FUNCTION, and teach pg_dump about it,
so that user-defined window functions are possible. For the moment you'll
have to write them in C, for lack of any interface to the WindowObject API
in the available PLs, but it's better than no support at all.
There was some debate about the best syntax for this. I ended up choosing
the "it's an attribute" position --- the other approach will inevitably be
more work, and the likely market for user-defined window functions is
probably too small to justify it.
Diffstat (limited to 'src/backend/commands/functioncmds.c')
-rw-r--r-- | src/backend/commands/functioncmds.c | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/backend/commands/functioncmds.c b/src/backend/commands/functioncmds.c index 8963f981178..13f1debf669 100644 --- a/src/backend/commands/functioncmds.c +++ b/src/backend/commands/functioncmds.c @@ -10,7 +10,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/functioncmds.c,v 1.104 2008/12/28 18:53:55 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/functioncmds.c,v 1.105 2008/12/31 02:25:03 tgl Exp $ * * DESCRIPTION * These routines take the parse tree and pick out the @@ -503,6 +503,7 @@ static void compute_attributes_sql_style(List *options, List **as, char **language, + bool *windowfunc_p, char *volatility_p, bool *strict_p, bool *security_definer, @@ -513,6 +514,7 @@ compute_attributes_sql_style(List *options, ListCell *option; DefElem *as_item = NULL; DefElem *language_item = NULL; + DefElem *windowfunc_item = NULL; DefElem *volatility_item = NULL; DefElem *strict_item = NULL; DefElem *security_item = NULL; @@ -540,6 +542,14 @@ compute_attributes_sql_style(List *options, errmsg("conflicting or redundant options"))); language_item = defel; } + else if (strcmp(defel->defname, "window") == 0) + { + if (windowfunc_item) + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("conflicting or redundant options"))); + windowfunc_item = defel; + } else if (compute_common_attribute(defel, &volatility_item, &strict_item, @@ -578,6 +588,8 @@ compute_attributes_sql_style(List *options, } /* process optional items */ + if (windowfunc_item) + *windowfunc_p = intVal(windowfunc_item->arg); if (volatility_item) *volatility_p = interpret_func_volatility(volatility_item); if (strict_item) @@ -735,7 +747,8 @@ CreateFunction(CreateFunctionStmt *stmt, const char *queryString) ArrayType *parameterNames; List *parameterDefaults; Oid requiredResultType; - bool isStrict, + bool isWindowFunc, + isStrict, security; char volatility; ArrayType *proconfig; @@ -756,6 +769,7 @@ CreateFunction(CreateFunctionStmt *stmt, const char *queryString) get_namespace_name(namespaceId)); /* default attributes */ + isWindowFunc = false; isStrict = false; security = false; volatility = PROVOLATILE_VOLATILE; @@ -766,7 +780,8 @@ CreateFunction(CreateFunctionStmt *stmt, const char *queryString) /* override attributes from explicit list */ compute_attributes_sql_style(stmt->options, &as_clause, &language, - &volatility, &isStrict, &security, + &isWindowFunc, &volatility, + &isStrict, &security, &proconfig, &procost, &prorows); /* Convert language name to canonical case */ @@ -892,6 +907,7 @@ CreateFunction(CreateFunctionStmt *stmt, const char *queryString) prosrc_str, /* converted to text later */ probin_str, /* converted to text later */ false, /* not an aggregate */ + isWindowFunc, security, isStrict, volatility, |