https://www.postgresql.org/docs/current/static/sql-altertable.html
- 是-相同的
ACCESS EXCLUSIVE
,默认值为NULL或未提及默认值时没有例外(我认为统计数据、"选项"、约束、集群要求不那么严格,但不需要添加列)
请注意,每个子窗体所需的锁定级别可能不同.一
- 否-它宁愿在 Select 时将NULL附加到结果
使用"添加列"添加列时,表中的所有现有行
- 没有,没有区别.这两种情况下的元数据变化(我认为这是一种用不同语义表示的情况)
编辑-演示:
db=# create table so(i int);
CREATE TABLE
Time: 9.498 ms
db=# insert into so select generate_series(1,10*1000*1000);
INSERT 0 10000000
Time: 13899.190 ms
db=# alter table so add column nd BOOLEAN;
ALTER TABLE
Time: 1025.178 ms
db=# alter table so add column dn BOOLEAN default null;
ALTER TABLE
Time: 13.849 ms
db=# alter table so add column dnn BOOLEAN default true;
ALTER TABLE
Time: 14988.450 ms
db=# select version();
version
----------------------------------------------------------------------------------------------------------------
PostgreSQL 9.6.1 on x86_64-apple-darwin15.6.0, compiled by Apple LLVM version 8.0.0 (clang-800.0.42.1), 64-bit
(1 row)
最后,为了避免猜测,它是特定于数据类型的:
db=# alter table so add column t text;
ALTER TABLE
Time: 25.831 ms
db=# alter table so add column tn text default null;
ALTER TABLE
Time: 13.798 ms
db=# alter table so add column tnn text default 'null';
ALTER TABLE
Time: 15440.318 ms