diff options
author | Tom Lane | 2013-03-11 18:26:05 +0000 |
---|---|---|
committer | Tom Lane | 2013-03-11 18:26:05 +0000 |
commit | 8f9cc41daf08be802933dc788517743719ee0949 (patch) | |
tree | 79e59fb2cc657208be862823b8c0bd69d33970b7 | |
parent | 41eef0ff75c3ea905513ae46f795c0409635fac8 (diff) |
Avoid generating bad remote SQL for INSERT ... DEFAULT VALUES.
"INSERT INTO foo() VALUES ()" is invalid syntax, so don't do that.
-rw-r--r-- | contrib/postgres_fdw/deparse.c | 52 |
1 files changed, 29 insertions, 23 deletions
diff --git a/contrib/postgres_fdw/deparse.c b/contrib/postgres_fdw/deparse.c index d667c997609..f5d723cc38a 100644 --- a/contrib/postgres_fdw/deparse.c +++ b/contrib/postgres_fdw/deparse.c @@ -505,38 +505,44 @@ deparseInsertSql(StringInfo buf, PlannerInfo *root, Index rtindex, appendStringInfoString(buf, "INSERT INTO "); deparseRelation(buf, rte->relid); - appendStringInfoString(buf, "("); - first = true; - foreach(lc, targetAttrs) + if (targetAttrs) { - int attnum = lfirst_int(lc); - Form_pg_attribute attr = tupdesc->attrs[attnum - 1]; + appendStringInfoString(buf, "("); - Assert(!attr->attisdropped); + first = true; + foreach(lc, targetAttrs) + { + int attnum = lfirst_int(lc); + Form_pg_attribute attr = tupdesc->attrs[attnum - 1]; - if (!first) - appendStringInfoString(buf, ", "); - first = false; + Assert(!attr->attisdropped); - deparseColumnRef(buf, rtindex, attnum, root); - } + if (!first) + appendStringInfoString(buf, ", "); + first = false; - appendStringInfoString(buf, ") VALUES ("); + deparseColumnRef(buf, rtindex, attnum, root); + } - pindex = 1; - first = true; - foreach(lc, targetAttrs) - { - if (!first) - appendStringInfoString(buf, ", "); - first = false; + appendStringInfoString(buf, ") VALUES ("); - appendStringInfo(buf, "$%d", pindex); - pindex++; - } + pindex = 1; + 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) deparseReturningList(buf, root, rtindex, rel, returningList); |