summaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2012-10-19 13:40:14 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2012-10-19 13:40:14 -0400
commitc47b40894d0a309a83a1f390ce0b6ae8959195db (patch)
tree2b51e7107db9901caea2e0fd49fb0fe19bd14ac8 /src/backend
parent95ff5b3599c3e88a70a45f3bb1e36f6c8762d450 (diff)
Fix ruleutils to print "INSERT INTO foo DEFAULT VALUES" correctly.
Per bug #7615 from Marko Tiikkaja. Apparently nobody ever tried this case before ...
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/utils/adt/ruleutils.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 1e83218952b..873c1911609 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -3196,8 +3196,8 @@ get_insert_query_def(Query *query, deparse_context *context)
List *strippedexprs;
/*
- * 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)
{
@@ -3231,7 +3231,7 @@ get_insert_query_def(Query *query, deparse_context *context)
context->indentLevel += PRETTYINDENT_STD;
appendStringInfoChar(buf, ' ');
}
- appendStringInfo(buf, "INSERT INTO %s (",
+ appendStringInfo(buf, "INSERT INTO %s ",
generate_relation_name(rte->relid, NIL));
/*
@@ -3248,6 +3248,8 @@ get_insert_query_def(Query *query, deparse_context *context)
values_cell = NULL;
strippedexprs = NIL;
sep = "";
+ if (query->targetList)
+ appendStringInfoChar(buf, '(');
foreach(l, query->targetList)
{
TargetEntry *tle = (TargetEntry *) lfirst(l);
@@ -3284,7 +3286,8 @@ get_insert_query_def(Query *query, deparse_context *context)
context, true));
}
}
- appendStringInfo(buf, ") ");
+ if (query->targetList)
+ appendStringInfo(buf, ") ");
if (select_rte)
{
@@ -3299,7 +3302,7 @@ get_insert_query_def(Query *query, deparse_context *context)
/* Add the multi-VALUES expression lists */
get_values_def(values_rte->values_lists, context);
}
- else
+ else if (strippedexprs)
{
/* A WITH clause is possible here */
get_with_clause(query, context);
@@ -3309,6 +3312,11 @@ get_insert_query_def(Query *query, deparse_context *context)
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)