in ext/pg_query/pg_query_deparse.c [1748:1822]
static void deparseIndexElem(StringInfo str, IndexElem* index_elem)
{
if (index_elem->name != NULL)
{
deparseColId(str, index_elem->name);
appendStringInfoChar(str, ' ');
}
else if (index_elem->expr != NULL)
{
switch (nodeTag(index_elem->expr))
{
case T_FuncCall:
case T_SQLValueFunction:
case T_TypeCast:
case T_CoalesceExpr:
case T_MinMaxExpr:
case T_XmlExpr:
case T_XmlSerialize:
deparseFuncExprWindowless(str, index_elem->expr);
break;
default:
appendStringInfoChar(str, '(');
deparseExpr(str, index_elem->expr);
appendStringInfoString(str, ") ");
}
}
else
{
Assert(false);
}
deparseOptCollate(str, index_elem->collation);
if (list_length(index_elem->opclass) > 0)
{
deparseAnyName(str, index_elem->opclass);
if (list_length(index_elem->opclassopts) > 0)
deparseRelOptions(str, index_elem->opclassopts);
appendStringInfoChar(str, ' ');
}
switch (index_elem->ordering)
{
case SORTBY_DEFAULT:
// Default
break;
case SORTBY_ASC:
appendStringInfoString(str, "ASC ");
break;
case SORTBY_DESC:
appendStringInfoString(str, "DESC ");
break;
case SORTBY_USING:
// Not allowed in CREATE INDEX
Assert(false);
break;
}
switch (index_elem->nulls_ordering)
{
case SORTBY_NULLS_DEFAULT:
// Default
break;
case SORTBY_NULLS_FIRST:
appendStringInfoString(str, "NULLS FIRST ");
break;
case SORTBY_NULLS_LAST:
appendStringInfoString(str, "NULLS LAST ");
break;
}
removeTrailingSpace(str);
}