1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-14 18:42:34 +03:00

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.
This commit is contained in:
Tom Lane
2008-12-31 02:25:06 +00:00
parent 8e8854daa2
commit 26ce4e85a1
9 changed files with 70 additions and 18 deletions

View File

@ -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,