static void deparseRangeFunction()

in ext/pg_query/pg_query_deparse.c [3084:3150]


static void deparseRangeFunction(StringInfo str, RangeFunction *range_func)
{
	ListCell *lc;
	ListCell *lc2;

	if (range_func->lateral)
		appendStringInfoString(str, "LATERAL ");

	if (range_func->is_rowsfrom)
	{
		appendStringInfoString(str, "ROWS FROM ");
		appendStringInfoChar(str, '(');
		foreach(lc, range_func->functions)
		{
			List *lfunc = castNode(List, lfirst(lc));
			Assert(list_length(lfunc) == 2);
			deparseFuncExprWindowless(str, linitial(lfunc));
			appendStringInfoChar(str, ' ');
			List *coldeflist = castNode(List, lsecond(lfunc));
			if (list_length(coldeflist) > 0)
			{
				appendStringInfoString(str, "AS (");
				foreach(lc2, coldeflist)
				{
					deparseColumnDef(str, castNode(ColumnDef, lfirst(lc2)));
					if (lnext(coldeflist, lc2))
						appendStringInfoString(str, ", ");
				}
				appendStringInfoChar(str, ')');
			}
			if (lnext(range_func->functions, lc))
				appendStringInfoString(str, ", ");
		}
		appendStringInfoChar(str, ')');
	}
	else
	{
		Assert(list_length(linitial(range_func->functions)) == 2);
		deparseFuncExprWindowless(str, linitial(linitial(range_func->functions)));
	}
	appendStringInfoChar(str, ' ');

	if (range_func->ordinality)
		appendStringInfoString(str, "WITH ORDINALITY ");

	if (range_func->alias != NULL)
	{
		deparseAlias(str, range_func->alias);
		appendStringInfoChar(str, ' ');
	}

	if (list_length(range_func->coldeflist) > 0)
	{
		if (range_func->alias == NULL)
			appendStringInfoString(str, "AS ");
		appendStringInfoChar(str, '(');
		foreach(lc, range_func->coldeflist)
		{
			deparseColumnDef(str, castNode(ColumnDef, lfirst(lc)));
			if (lnext(range_func->coldeflist, lc))
				appendStringInfoString(str, ", ");
		}
		appendStringInfoChar(str, ')');
	}

	removeTrailingSpace(str);
}