Skip to content
Snippets Groups Projects
Commit 8f9cc41d authored by Tom Lane's avatar Tom Lane
Browse files

Avoid generating bad remote SQL for INSERT ... DEFAULT VALUES.

"INSERT INTO foo() VALUES ()" is invalid syntax, so don't do that.
parent 41eef0ff
No related branches found
No related tags found
No related merge requests found
...@@ -505,38 +505,44 @@ deparseInsertSql(StringInfo buf, PlannerInfo *root, Index rtindex, ...@@ -505,38 +505,44 @@ deparseInsertSql(StringInfo buf, PlannerInfo *root, Index rtindex,
appendStringInfoString(buf, "INSERT INTO "); appendStringInfoString(buf, "INSERT INTO ");
deparseRelation(buf, rte->relid); deparseRelation(buf, rte->relid);
appendStringInfoString(buf, "(");
first = true; if (targetAttrs)
foreach(lc, targetAttrs)
{ {
int attnum = lfirst_int(lc); appendStringInfoString(buf, "(");
Form_pg_attribute attr = tupdesc->attrs[attnum - 1];
Assert(!attr->attisdropped); first = true;
foreach(lc, targetAttrs)
{
int attnum = lfirst_int(lc);
Form_pg_attribute attr = tupdesc->attrs[attnum - 1];
if (!first) Assert(!attr->attisdropped);
appendStringInfoString(buf, ", ");
first = false;
deparseColumnRef(buf, rtindex, attnum, root); if (!first)
} appendStringInfoString(buf, ", ");
first = false;
appendStringInfoString(buf, ") VALUES ("); deparseColumnRef(buf, rtindex, attnum, root);
}
pindex = 1; appendStringInfoString(buf, ") VALUES (");
first = true;
foreach(lc, targetAttrs)
{
if (!first)
appendStringInfoString(buf, ", ");
first = false;
appendStringInfo(buf, "$%d", pindex); pindex = 1;
pindex++; first = true;
} foreach(lc, targetAttrs)
{
if (!first)
appendStringInfoString(buf, ", ");
first = false;
appendStringInfo(buf, "$%d", pindex);
pindex++;
}
appendStringInfoString(buf, ")"); appendStringInfoString(buf, ")");
}
else
appendStringInfoString(buf, " DEFAULT VALUES");
if (returningList) if (returningList)
deparseReturningList(buf, root, rtindex, rel, returningList); deparseReturningList(buf, root, rtindex, rel, returningList);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment