何时使用NULL以及何时使用NOT NULL DEFAULT'' [英] when to use NULL and when to NOT NULL DEFAULT ''

查看:88
本文介绍了何时使用NULL以及何时使用NOT NULL DEFAULT''的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PG peps:


流行的智慧和优势是什么?关于何时让

a varchar(或任何)列为NULL的最佳实践建议,以及何时使其为NOT NULL

DEFAULT''''(或'0000 -00-00''或其他什么) - 在PostgreSQL中?


{从MySQL迁移到PG,我们总是建议使用NOT NULL

来保存一个字节或什么的。但那是多年前为

这个愚蠢的问题感到抱歉,但我不得不问。}


--------- ------------------(广播结束)---------------------------

提示1:订阅和取消订阅命令转到 ma*******@postgresql.org

解决方案

Am Freitag,8。Oktober 2004 07:22 schrieb Miles Keaton:

普遍存在的智慧是什么?关于何时让varchar(或任何)列为NULL,以及何时使其为NOT NULL的最佳实践建议
DEFAULT''''(或'''0000-00-00''或无论如何) - 在PostgreSQL中?




简单地说,你总是做第一个而不做第二个。


-

Peter Eisentraut
http://developer.postgresql .org / ~petere /

---------------------------(广播结束)---------------------------

提示3:如果通过Usenet发布/阅读,请发送适当的

subscribe-nomail命令到 ma ******* @ postgresql.org 这样你的

消息就可以干净地进入邮件列表


为什么你永远不会将列定义为NOT NULL,或者我误解了你说的是什么?

周五08 2004年10月06:07 am,Peter Eisentraut说:


简而言之,你总是做第一个而不做第二个。

-
Peter Eisentraut
http://developer.postgresql.org/~petere/

---------------------------(播出结束)------- --------------------
提示3:如果通过Usenet发布/阅读,请发送适当的
subscribe-nomail命令到 ma ******* @ postgresql.org ,以便您的消息可以干净地通过邮件列表




-


工作:1-336-372-6812

手机:1 -336-363-4719

电子邮件: te***@esc1.com


---------------------------(广播结束)----------- ----------------

提示9:计划者将忽略您选择索引的愿望扫描你的

加入列的数据类型是否匹配


顺便说一下,MySQL手册用来推荐(或者仍然是?)尽可能将所有

列定义为NOT NULL,因为NULL很慢...... :-)


对我来说它''很明显,如果你永远不会允许列

有一个未知值,那么定义它NOT NULL让数据库

保证。否则,它可以为空。


Terry Lee Tucker写道:

为什么你永远不会将列定义为NOT NULL,或者我误解了什么
你说的是什么?

2004年10月8日星期五上午06:07,Peter Eisentraut说:

简而言之,你总是做第一个,从不这样做第二。




-

dave

--------- ------------------(广播结束)---------------------------

提示9:如果您的

加入列的数据类型不匹配,计划员将忽略您选择索引扫描的愿望


PG peeps:

What''s the prevailing wisdom & best-practice advice about when to let
a varchar (or any) column be NULL, and when to make it NOT NULL
DEFAULT '''' (or ''0000-00-00'' or whatever) - in PostgreSQL?

{Moving to PG from MySQL where we were always advised to use NOT NULL
to save a byte or something. But that was years ago so sorry for the
stupid-sounding question, but I had to ask.}

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

解决方案

Am Freitag, 8. Oktober 2004 07:22 schrieb Miles Keaton:

What''s the prevailing wisdom & best-practice advice about when to let
a varchar (or any) column be NULL, and when to make it NOT NULL
DEFAULT '''' (or ''0000-00-00'' or whatever) - in PostgreSQL?



Briefly, you always do the first and never do the second.

--
Peter Eisentraut
http://developer.postgresql.org/~petere/

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly


Why would you never define a column as NOT NULL, or am I misunderstanding what
you are saying?

On Friday 08 October 2004 06:07 am, Peter Eisentraut saith:


Briefly, you always do the first and never do the second.

--
Peter Eisentraut
http://developer.postgresql.org/~petere/

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly



--

Work: 1-336-372-6812
Cell: 1-336-363-4719
email: te***@esc1.com

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column''s datatypes do not match


Btw, MySQL manual used to recommend (or still does?) defining all
columns as NOT NULL as much as possible, "because NULL is slow"... :-)

For me it''s pretty obvious, if you are never going to allow the column
to have an "unknown value", then define it NOT NULL to let the database
guarantee that. Otherwise, nullable it is.

Terry Lee Tucker wrote:

Why would you never define a column as NOT NULL, or am I misunderstanding what
you are saying?

On Friday 08 October 2004 06:07 am, Peter Eisentraut saith:

Briefly, you always do the first and never do the second.



--
dave
---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column''s datatypes do not match


这篇关于何时使用NULL以及何时使用NOT NULL DEFAULT''的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆