mirror of
https://github.com/postgres/postgres.git
synced 2025-10-13 18:28:01 +03:00
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.
This commit is contained in:
@@ -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, ')');
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user