【发布时间】:2018-10-09 13:03:21
【问题描述】:
我是 MySQL 的 Postgres 新手。
我创建了一个表,其中的列“col”默认为空。
CREATE TABLE widgets (id serial primary key, col bigint default null);
CREATE TABLE
test=# \d+ widgets;
Table "public.widgets"
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
--------+---------+-----------+----------+-------------------------------------+---------+--------------+-------------
id | integer | | not null | nextval('widgets_id_seq'::regclass) | plain | |
col | bigint | | | | plain | |
Indexes:
"widgets_pkey" PRIMARY KEY, btree (id)
test=#
但是,在 Default 列中没有任何内容表明它是一个空字段。
默认值是否应该在模式输出中显示为 null?
我也尝试了上面相同的示例,但使用了default 99。键入 \d+ 时,默认列中不显示任何内容。在该示例中,我插入一行 INSERT INTO widgets (id) VALUES (1); 它获取默认值 99,因此我知道正在使用默认值(至少对于整数值)。
更新:默认列实际上显示 99。我使用了带有自动完成功能的 \d+ 并查看了错误的表格。
使用default null,当我SELECT * FROM widgets 时,该列显示为空白。
Postgres 是否没有明确显示标记为“null”的值?如果不是,如何区分空文本字段和具有空值的字段?
【问题讨论】:
标签: postgresql