Skip to content

Commit 8f9cc41

Browse files
committed
Avoid generating bad remote SQL for INSERT ... DEFAULT VALUES.
"INSERT INTO foo() VALUES ()" is invalid syntax, so don't do that.
1 parent 41eef0f commit 8f9cc41

File tree

1 file changed

+29
-23
lines changed

1 file changed

+29
-23
lines changed

contrib/postgres_fdw/deparse.c

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -505,38 +505,44 @@ deparseInsertSql(StringInfo buf, PlannerInfo *root, Index rtindex,
505505

506506
appendStringInfoString(buf, "INSERT INTO ");
507507
deparseRelation(buf, rte->relid);
508-
appendStringInfoString(buf, "(");
509508

510-
first = true;
511-
foreach(lc, targetAttrs)
509+
if (targetAttrs)
512510
{
513-
int attnum = lfirst_int(lc);
514-
Form_pg_attribute attr = tupdesc->attrs[attnum - 1];
511+
appendStringInfoString(buf, "(");
515512

516-
Assert(!attr->attisdropped);
513+
first = true;
514+
foreach(lc, targetAttrs)
515+
{
516+
int attnum = lfirst_int(lc);
517+
Form_pg_attribute attr = tupdesc->attrs[attnum - 1];
517518

518-
if (!first)
519-
appendStringInfoString(buf, ", ");
520-
first = false;
519+
Assert(!attr->attisdropped);
521520

522-
deparseColumnRef(buf, rtindex, attnum, root);
523-
}
521+
if (!first)
522+
appendStringInfoString(buf, ", ");
523+
first = false;
524524

525-
appendStringInfoString(buf, ") VALUES (");
525+
deparseColumnRef(buf, rtindex, attnum, root);
526+
}
526527

527-
pindex = 1;
528-
first = true;
529-
foreach(lc, targetAttrs)
530-
{
531-
if (!first)
532-
appendStringInfoString(buf, ", ");
533-
first = false;
528+
appendStringInfoString(buf, ") VALUES (");
534529

535-
appendStringInfo(buf, "$%d", pindex);
536-
pindex++;
537-
}
530+
pindex = 1;
531+
first = true;
532+
foreach(lc, targetAttrs)
533+
{
534+
if (!first)
535+
appendStringInfoString(buf, ", ");
536+
first = false;
537+
538+
appendStringInfo(buf, "$%d", pindex);
539+
pindex++;
540+
}
538541

539-
appendStringInfoString(buf, ")");
542+
appendStringInfoString(buf, ")");
543+
}
544+
else
545+
appendStringInfoString(buf, " DEFAULT VALUES");
540546

541547
if (returningList)
542548
deparseReturningList(buf, root, rtindex, rel, returningList);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy