Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2008-12-31 02:25:06 +0000
committerTom Lane2008-12-31 02:25:06 +0000
commit26ce4e85a1605326f29e3cb0cc715ddf522a753a (patch)
treebfd2ca91df26e9aff0873e0c59ce20d3ae096621 /src/backend
parent8e8854daa2b4b3ef9e3fc1a56c79608a70018058 (diff)
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')
-rw-r--r--src/backend/catalog/pg_aggregate.c3
-rw-r--r--src/backend/catalog/pg_proc.c7
-rw-r--r--src/backend/commands/functioncmds.c22
-rw-r--r--src/backend/commands/proclang.c4
-rw-r--r--src/backend/parser/gram.y6
-rw-r--r--src/backend/utils/adt/ruleutils.c4
6 files changed, 35 insertions, 11 deletions
diff --git a/src/backend/catalog/pg_aggregate.c b/src/backend/catalog/pg_aggregate.c
index 414366bc54e..8aad4a0ea44 100644
--- a/src/backend/catalog/pg_aggregate.c
+++ b/src/backend/catalog/pg_aggregate.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/catalog/pg_aggregate.c,v 1.99 2008/12/18 18:20:33 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/catalog/pg_aggregate.c,v 1.100 2008/12/31 02:25:03 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -217,6 +217,7 @@ AggregateCreate(const char *aggName,
"aggregate_dummy", /* placeholder proc */
NULL, /* probin */
true, /* isAgg */
+ false, /* isWindowFunc */
false, /* security invoker (currently not
* definable for agg) */
false, /* isStrict (not needed for agg) */
diff --git a/src/backend/catalog/pg_proc.c b/src/backend/catalog/pg_proc.c
index 8ff22c23c9e..d11a067a5d9 100644
--- a/src/backend/catalog/pg_proc.c
+++ b/src/backend/catalog/pg_proc.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/catalog/pg_proc.c,v 1.158 2008/12/28 18:53:54 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/catalog/pg_proc.c,v 1.159 2008/12/31 02:25:03 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -53,7 +53,7 @@ static bool match_prosrc_to_literal(const char *prosrc, const char *literal,
*
* Note: allParameterTypes, parameterModes, parameterNames, and proconfig
* are either arrays of the proper types or NULL. We declare them Datum,
- * not "ArrayType *", to avoid importing array.h into pg_proc.h.
+ * not "ArrayType *", to avoid importing array.h into pg_proc_fn.h.
* ----------------------------------------------------------------
*/
Oid
@@ -67,6 +67,7 @@ ProcedureCreate(const char *procedureName,
const char *prosrc,
const char *probin,
bool isAgg,
+ bool isWindowFunc,
bool security_definer,
bool isStrict,
char volatility,
@@ -80,8 +81,6 @@ ProcedureCreate(const char *procedureName,
float4 prorows)
{
Oid retval;
- /* XXX we don't currently have a way to make new window functions */
- bool isWindowFunc = false;
int parameterCount;
int allParamCount;
Oid *allParams;
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,
diff --git a/src/backend/commands/proclang.c b/src/backend/commands/proclang.c
index 3188156c4d1..ea37352b419 100644
--- a/src/backend/commands/proclang.c
+++ b/src/backend/commands/proclang.c
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/proclang.c,v 1.82 2008/12/18 18:20:33 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/proclang.c,v 1.83 2008/12/31 02:25:03 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -140,6 +140,7 @@ CreateProceduralLanguage(CreatePLangStmt *stmt)
pltemplate->tmplhandler,
pltemplate->tmpllibrary,
false, /* isAgg */
+ false, /* isWindowFunc */
false, /* security_definer */
false, /* isStrict */
PROVOLATILE_VOLATILE,
@@ -174,6 +175,7 @@ CreateProceduralLanguage(CreatePLangStmt *stmt)
pltemplate->tmplvalidator,
pltemplate->tmpllibrary,
false, /* isAgg */
+ false, /* isWindowFunc */
false, /* security_definer */
false, /* isStrict */
PROVOLATILE_VOLATILE,
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index 34dc40a1056..011041f3037 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.649 2008/12/31 00:08:36 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.650 2008/12/31 02:25:04 tgl Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
@@ -4801,6 +4801,10 @@ createfunc_opt_item:
{
$$ = makeDefElem("language", (Node *)makeString($2));
}
+ | WINDOW
+ {
+ $$ = makeDefElem("window", (Node *)makeInteger(TRUE));
+ }
| common_func_opt_item
{
$$ = $1;
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 4a44b733cf3..f48ee4ae96d 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.292 2008/12/31 00:08:37 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.293 2008/12/31 02:25:04 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1466,6 +1466,8 @@ pg_get_functiondef(PG_FUNCTION_ARGS)
/* Emit some miscellaneous options on one line */
oldlen = buf.len;
+ if (proc->proiswindow)
+ appendStringInfoString(&buf, " WINDOW");
switch (proc->provolatile)
{
case PROVOLATILE_IMMUTABLE: