mirror of
https://github.com/postgres/postgres.git
synced 2025-06-07 11:02:12 +03:00
Fix ruleutils to print "INSERT INTO foo DEFAULT VALUES" correctly.
Per bug #7615 from Marko Tiikkaja. Apparently nobody ever tried this case before ...
This commit is contained in:
parent
d2a5f32656
commit
823f83d3d5
@ -3390,8 +3390,8 @@ get_insert_query_def(Query *query, deparse_context *context)
|
|||||||
get_with_clause(query, context);
|
get_with_clause(query, context);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If it's an INSERT ... SELECT or VALUES (...), (...), ... there will be
|
* If it's an INSERT ... SELECT or multi-row VALUES, there will be a
|
||||||
* a single RTE for the SELECT or VALUES.
|
* single RTE for the SELECT or VALUES. Plain VALUES has neither.
|
||||||
*/
|
*/
|
||||||
foreach(l, query->rtable)
|
foreach(l, query->rtable)
|
||||||
{
|
{
|
||||||
@ -3425,7 +3425,7 @@ get_insert_query_def(Query *query, deparse_context *context)
|
|||||||
context->indentLevel += PRETTYINDENT_STD;
|
context->indentLevel += PRETTYINDENT_STD;
|
||||||
appendStringInfoChar(buf, ' ');
|
appendStringInfoChar(buf, ' ');
|
||||||
}
|
}
|
||||||
appendStringInfo(buf, "INSERT INTO %s (",
|
appendStringInfo(buf, "INSERT INTO %s ",
|
||||||
generate_relation_name(rte->relid, NIL));
|
generate_relation_name(rte->relid, NIL));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -3442,6 +3442,8 @@ get_insert_query_def(Query *query, deparse_context *context)
|
|||||||
values_cell = NULL;
|
values_cell = NULL;
|
||||||
strippedexprs = NIL;
|
strippedexprs = NIL;
|
||||||
sep = "";
|
sep = "";
|
||||||
|
if (query->targetList)
|
||||||
|
appendStringInfoChar(buf, '(');
|
||||||
foreach(l, query->targetList)
|
foreach(l, query->targetList)
|
||||||
{
|
{
|
||||||
TargetEntry *tle = (TargetEntry *) lfirst(l);
|
TargetEntry *tle = (TargetEntry *) lfirst(l);
|
||||||
@ -3478,6 +3480,7 @@ get_insert_query_def(Query *query, deparse_context *context)
|
|||||||
context, true));
|
context, true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (query->targetList)
|
||||||
appendStringInfo(buf, ") ");
|
appendStringInfo(buf, ") ");
|
||||||
|
|
||||||
if (select_rte)
|
if (select_rte)
|
||||||
@ -3491,7 +3494,7 @@ get_insert_query_def(Query *query, deparse_context *context)
|
|||||||
/* Add the multi-VALUES expression lists */
|
/* Add the multi-VALUES expression lists */
|
||||||
get_values_def(values_rte->values_lists, context);
|
get_values_def(values_rte->values_lists, context);
|
||||||
}
|
}
|
||||||
else
|
else if (strippedexprs)
|
||||||
{
|
{
|
||||||
/* Add the single-VALUES expression list */
|
/* Add the single-VALUES expression list */
|
||||||
appendContextKeyword(context, "VALUES (",
|
appendContextKeyword(context, "VALUES (",
|
||||||
@ -3499,6 +3502,11 @@ get_insert_query_def(Query *query, deparse_context *context)
|
|||||||
get_rule_expr((Node *) strippedexprs, context, false);
|
get_rule_expr((Node *) strippedexprs, context, false);
|
||||||
appendStringInfoChar(buf, ')');
|
appendStringInfoChar(buf, ')');
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* No expressions, so it must be DEFAULT VALUES */
|
||||||
|
appendStringInfo(buf, "DEFAULT VALUES");
|
||||||
|
}
|
||||||
|
|
||||||
/* Add RETURNING if present */
|
/* Add RETURNING if present */
|
||||||
if (query->returningList)
|
if (query->returningList)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user