aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2012-10-19 13:40:05 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2012-10-19 13:40:05 -0400
commit823f83d3d53ad2c0e799b1953ed9a1955840f11c (patch)
tree9289dc70d41356def1e692ee83c17ac95e39f1e3
parentd2a5f326568dfe98559319db6f3b9d08f0c851cc (diff)
downloadpostgresql-823f83d3d53ad2c0e799b1953ed9a1955840f11c.tar.gz
postgresql-823f83d3d53ad2c0e799b1953ed9a1955840f11c.zip
Fix ruleutils to print "INSERT INTO foo DEFAULT VALUES" correctly.
Per bug #7615 from Marko Tiikkaja. Apparently nobody ever tried this case before ...
-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 77600c33f02..3a3f7fb71d7 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -3390,8 +3390,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)
{
@@ -3425,7 +3425,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));
/*
@@ -3442,6 +3442,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);
@@ -3478,7 +3480,8 @@ get_insert_query_def(Query *query, deparse_context *context)
context, true));
}
}
- appendStringInfo(buf, ") ");
+ if (query->targetList)
+ appendStringInfo(buf, ") ");
if (select_rte)
{
@@ -3491,7 +3494,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 (",
@@ -3499,6 +3502,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)