gpt4 book ai didi

postgresql - 如何创建接受 NULL 的域?

转载 作者:行者123 更新时间:2023-11-29 12:38:47 24 4
gpt4 key购买 nike

我似乎无法弄清楚如何获得 custom domain接受 NULL 值。请注意,对于狗屎和傻笑,我已经尝试了许多不同的方法:

DROP SCHEMA census CASCADE;
CREATE SCHEMA census;
-- FIRST FOUR METHODS: NULL before CHECK, in CHECK, and NULL after CHECK
CREATE DOMAIN census.sex AS text NULL CHECK ( VALUE IN ('M', 'F', 'NULL') OR VALUE IS NULL ) NULL;
CREATE TABLE census.names (
name text
, freq int
, cumfreq float
, rank float
, is_last bool
, sex census.sex NULL -- fourth way
, PRIMARY KEY ( is_last, sex, name )
);

但是,仍然没有运气......

# \d census.names;
Table "census.names"
Column | Type | Modifiers
---------+------------------+-----------
name | text | not null
freq | integer |
cumfreq | double precision |
rank | double precision |
is_last | boolean | not null
sex | census.sex | not null
Indexes:
"names_pkey" PRIMARY KEY, btree (is_last, sex, name)

更有趣的是,the docs

NULL

Values of this domain are allowed to be null. This is the default.

This clause is only intended for compatibility with nonstandard SQL databases. Its use is discouraged in new applications.

没有子句它仍然显示 NOT NULL

$ psql --version
psql (PostgreSQL) 9.1.1
contains support for command-line editing

最佳答案

像往常一样:

  1. 在 StackOverflow 上发布一个描述性问题
  2. 将链接粘贴到 irc://irc.freenode.net/#postgresql
  3. 让专家在几秒钟内回答问题。

11:17 < RhodiumToad> EvanCarroll: it's the primary key that does it - all columns of a primary key are not null

他什么都知道。

关于postgresql - 如何创建接受 NULL 的域?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8854456/

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