diff --git a/src/backend/rewrite/rewriteHandler.c b/src/backend/rewrite/rewriteHandler.c new file mode 100644 index e1d805d..06f9742 --- a/src/backend/rewrite/rewriteHandler.c +++ b/src/backend/rewrite/rewriteHandler.c @@ -724,11 +724,15 @@ adjustJoinTreeList(Query *parsetree, boo * attributes that have defaults and are not assigned to in the given tlist. * (We do not insert anything for default-less attributes, however. The * planner will later insert NULLs for them, but there's no reason to slow - * down rewriter processing with extra tlist nodes.) Also, for both INSERT - * and UPDATE, replace explicit DEFAULT specifications with column default - * expressions. + * down rewriter processing with extra tlist nodes. We also do not insert + * anything for stored generated columns; those are fixed up in the executor.) * - * 2. Merge multiple entries for the same target attribute, or declare error + * 2. For INSERT and UPDATE, process any set-to-DEFAULT tlist entries. Any + * entries for columns that have defaults are replaced with the column default + * expressions, and any entries for default-less or stored generated columns + * are removed (for the same reasons as above). + * + * 3. Merge multiple entries for the same target attribute, or declare error * if we can't. Multiple entries are only allowed for INSERT/UPDATE of * portions of an array or record field, for example * UPDATE table SET foo[2] = 42, foo[4] = 43; @@ -736,11 +740,11 @@ adjustJoinTreeList(Query *parsetree, boo * the expression we want to produce in this case is like * foo = array_set_element(array_set_element(foo, 2, 42), 4, 43) * - * 3. Sort the tlist into standard order: non-junk fields in order by resno, + * 4. Sort the tlist into standard order: non-junk fields in order by resno, * then junk fields (these in no particular order). * - * We must do items 1 and 2 before firing rewrite rules, else rewritten - * references to NEW.foo will produce wrong or incomplete results. Item 3 + * We must do items 1, 2, and 3 before firing rewrite rules, else rewritten + * references to NEW.foo will produce wrong or incomplete results. Item 4 * is not needed for rewriting, but it is helpful for the planner, and we * can do it essentially for free while handling the other items. *