get_with_clause(query, context);
/*
- * If it's an INSERT ... SELECT or VALUES (...), (...), ... there will be
- * a single RTE for the SELECT or VALUES.
+ * If it's an INSERT ... SELECT or multi-row VALUES, there will be a
+ * single RTE for the SELECT or VALUES. Plain VALUES has neither.
*/
foreach(l, query->rtable)
{
context->indentLevel += PRETTYINDENT_STD;
appendStringInfoChar(buf, ' ');
}
- appendStringInfo(buf, "INSERT INTO %s (",
+ appendStringInfo(buf, "INSERT INTO %s ",
generate_relation_name(rte->relid, NIL));
/*
values_cell = NULL;
strippedexprs = NIL;
sep = "";
+ if (query->targetList)
+ appendStringInfoChar(buf, '(');
foreach(l, query->targetList)
{
TargetEntry *tle = (TargetEntry *) lfirst(l);
context, true));
}
}
- appendStringInfo(buf, ") ");
+ if (query->targetList)
+ appendStringInfo(buf, ") ");
if (select_rte)
{
/* Add the multi-VALUES expression lists */
get_values_def(values_rte->values_lists, context);
}
- else
+ else if (strippedexprs)
{
/* Add the single-VALUES expression list */
appendContextKeyword(context, "VALUES (",
get_rule_expr((Node *) strippedexprs, context, false);
appendStringInfoChar(buf, ')');
}
+ else
+ {
+ /* No expressions, so it must be DEFAULT VALUES */
+ appendStringInfo(buf, "DEFAULT VALUES");
+ }
/* Add RETURNING if present */
if (query->returningList)