aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2012-10-19 13:39:51 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2012-10-19 13:39:51 -0400
commit0d6895051a2e53026ad0daae0ebc3cb901acc521 (patch)
tree385a33d5cf9bb6cd3ba95acdf97e6c0838b8dbfa /src
parentda85727565818d95ee9cb16ca1c4c4e570c6e2cd (diff)
downloadpostgresql-0d6895051a2e53026ad0daae0ebc3cb901acc521.tar.gz
postgresql-0d6895051a2e53026ad0daae0ebc3cb901acc521.zip
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')
-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 c3ede233bcd..b7aff1189b2 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -3690,8 +3690,8 @@ get_insert_query_def(Query *query, deparse_context *context)
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)
{
@@ -3725,7 +3725,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));
/*
@@ -3742,6 +3742,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);
@@ -3778,7 +3780,8 @@ get_insert_query_def(Query *query, deparse_context *context)
context, true));
}
}
- appendStringInfo(buf, ") ");
+ if (query->targetList)
+ appendStringInfo(buf, ") ");
if (select_rte)
{
@@ -3791,7 +3794,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)
{
/* Add the single-VALUES expression list */
appendContextKeyword(context, "VALUES (",
@@ -3799,6 +3802,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)