diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2008-12-31 00:08:39 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2008-12-31 00:08:39 +0000 |
commit | 8e8854daa2b4b3ef9e3fc1a56c79608a70018058 (patch) | |
tree | a6c4cf4b43acc764a38071843c10dc3edb3ca32e /src/backend/utils/adt/ruleutils.c | |
parent | 0fb9be7acfb31ba38c1bbdd7883d5d03f6e261e5 (diff) | |
download | postgresql-8e8854daa2b4b3ef9e3fc1a56c79608a70018058.tar.gz postgresql-8e8854daa2b4b3ef9e3fc1a56c79608a70018058.zip |
Add some basic support for window frame clauses to the window-functions
patch. This includes the ability to force the frame to cover the whole
partition, and the ability to make the frame end exactly on the current row
rather than its last ORDER BY peer. Supporting any more of the full SQL
frame-clause syntax will require nontrivial hacking on the window aggregate
code, so it'll have to wait for 8.5 or beyond.
Diffstat (limited to 'src/backend/utils/adt/ruleutils.c')
-rw-r--r-- | src/backend/utils/adt/ruleutils.c | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index 969977cea51..4a44b733cf3 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.291 2008/12/28 18:53:59 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.292 2008/12/31 00:08:37 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -2903,7 +2903,7 @@ get_rule_windowspec(WindowClause *wc, List *targetList, appendStringInfoString(buf, quote_identifier(wc->refname)); needspace = true; } - /* partitions are always inherited, so only print if no refname */ + /* partition clauses are always inherited, so only print if no refname */ if (wc->partitionClause && !wc->refname) { if (needspace) @@ -2921,6 +2921,7 @@ get_rule_windowspec(WindowClause *wc, List *targetList, } needspace = true; } + /* print ordering clause only if not inherited */ if (wc->orderClause && !wc->copiedOrder) { if (needspace) @@ -2929,6 +2930,38 @@ get_rule_windowspec(WindowClause *wc, List *targetList, get_rule_orderby(wc->orderClause, targetList, false, context); needspace = true; } + /* framing clause is never inherited, so print unless it's default */ + if (wc->frameOptions & FRAMEOPTION_NONDEFAULT) + { + if (needspace) + appendStringInfoChar(buf, ' '); + if (wc->frameOptions & FRAMEOPTION_RANGE) + appendStringInfoString(buf, "RANGE "); + else if (wc->frameOptions & FRAMEOPTION_ROWS) + appendStringInfoString(buf, "ROWS "); + else + Assert(false); + if (wc->frameOptions & FRAMEOPTION_BETWEEN) + appendStringInfoString(buf, "BETWEEN "); + if (wc->frameOptions & FRAMEOPTION_START_UNBOUNDED_PRECEDING) + appendStringInfoString(buf, "UNBOUNDED PRECEDING "); + else if (wc->frameOptions & FRAMEOPTION_START_CURRENT_ROW) + appendStringInfoString(buf, "CURRENT ROW "); + else + Assert(false); + if (wc->frameOptions & FRAMEOPTION_BETWEEN) + { + appendStringInfoString(buf, "AND "); + if (wc->frameOptions & FRAMEOPTION_END_UNBOUNDED_FOLLOWING) + appendStringInfoString(buf, "UNBOUNDED FOLLOWING "); + else if (wc->frameOptions & FRAMEOPTION_END_CURRENT_ROW) + appendStringInfoString(buf, "CURRENT ROW "); + else + Assert(false); + } + /* we will now have a trailing space; remove it */ + buf->len--; + } appendStringInfoChar(buf, ')'); } |