gpt4 book ai didi

postgresql - Postgres : how does a default value get populated?

转载 作者:行者123 更新时间:2023-11-29 14:28:59 26 4
gpt4 key购买 nike

明确地说,我想知道用于填充默认值的机制是什么,而不是在表上创建默认值约束所需的 SQL 语法。

Postgres 是否使用某种触发器来更新默认值(如果缺少或其他原因)?我找不到关于 official website 的解释.

最佳答案

这发生在 src/backend/rewrite/rewriteHandler.c 中的 rewriteTargetListIU 函数中.评论说明了一切:

/*
* 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 字符串和优化它之间的步骤。

关于postgresql - Postgres : how does a default value get populated?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54447851/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com