0

为了清楚起见,我想知道用于填充默认值的机制是什么,而不是在表上创建默认值约束所需的 SQL 语法。

Postgres 是否使用某种触发器来更新默认值(如果缺失或其他原因)?我在官方网站上找不到解释。

4

1 回答 1

2

这发生rewriteTargetListIUsrc/backend/rewrite/rewriteHandler.c. 评论说明了一切:

/*
 * rewriteTargetListIU - rewrite INSERT/UPDATE targetlist into standard form
 *
 * This has the following responsibilities:
 *
 * 1. For an INSERT, add tlist entries to compute default values for any
 * 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.

所以这发生在查询重写期间,这是解析 SQL 字符串和优化它之间的步骤。

于 2019-01-31T11:17:47.403 回答