如何设置默认值" 0000-00-00对于“日期”在PostgreSQL下输入? [英] How to setup default value "0000-00-00" for "date" type under PostgreSQL?

查看:103
本文介绍了如何设置默认值" 0000-00-00对于“日期”在PostgreSQL下输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我有一个关于日期的问题&安培; "时间戳" PostgreSQL中的类型。我想要

来设置默认值''0000-00-00''和'0000-00-00 00:00:00"对于

他们。但是,似乎PostgreSQL不支持它。可以

有人帮我吗?


示例表:


T1(col1 varchar(7)没有null,

col2 varchar(4)not null,

col3 date not null,

col 4 varchar(3),

主键(col1,col2,col3)



在我的设计模型中,col3必须是主要关键部分之一。由于在数据填充开始时

,我们不知道

" col3"的价值。 col3的值通过GUI输入。因此,当我使用

MySQL时,我给出的默认值是0000-00-00。但是,在我将
迁移到postgreSQL后,我无法将默认值设置为

" 0000-00-00"更多。请问有人可以帮我吗?我真的

想知道如何保存''0000-00-00''作为date的默认值

和timestamp类型。


非常感谢!

Emi Lu



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

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

subscribe-nomail命令给 ma ******* @ postgresql.org ,以便您的

消息可以干净地通过邮件列表

Hello all,

I have a question about "date" & "timestamp" types in PostgreSQL. I want
to setup the default value ''0000-00-00'' and "0000-00-00 00:00:00" for
them. However, it seems that PostgreSQL does not support it. Could
someone helps me please?

The example table:

T1 (col1 varchar(7) not null,
col2 varchar(4) not null,
col3 date not null,
col 4 varchar(3),
primary key(col1, col2, col3)
)
In my design model, "col3" has to be one of the primary key part. Since
at the beginning of the data population, we do not know the value of
"col3"; values for "col3" are input throught GUI. Therefore, when I use
MySQL, the default values I gave is "0000-00-00". However, after I
migrate to postgreSQL, I could not setup the default values as
"0000-00-00" any more. Could somebody help me about it please? I really
want to know how I can save ''0000-00-00'' as the default value for "date"
and "timestamp" types.

Thanks a lot!
Emi Lu


---------------------------(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

推荐答案

>我真的
想知道如何保存''0000-00-00''作为date
和timestamp的默认值。类型。
want to know how I can save ''0000-00-00'' as the default value for "date"
and "timestamp" types.



你不能。它们是无效的日期。


Karsten

-

GPG密钥ID E4071346 @ wwwkeys.pgp.net

E167 67FD A291 2BEA 73BD 4537 78B9 A9F9 E407 1346

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

提示9:计划者将忽略如果您的

加入列的数据类型不匹配,您希望选择索引扫描


You can not. They are invalid dates.

Karsten
--
GPG key ID E4071346 @ wwwkeys.pgp.net
E167 67FD A291 2BEA 73BD 4537 78B9 A9F9 E407 1346

---------------------------(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


8月18日星期三2004年,Emi Lu写道:
On Wed, 18 Aug 2004, Emi Lu wrote:
大家好,

我有一个关于日期的问题。 &安培; "时间戳" PostgreSQL中的类型。我想设置默认值''0000-00-00''和'0000-00-00 00:00:00"但是,似乎PostgreSQL不支持它。有人可以帮助我吗?
Hello all,

I have a question about "date" & "timestamp" types in PostgreSQL. I want to
setup the default value ''0000-00-00'' and "0000-00-00 00:00:00" for them.
However, it seems that PostgreSQL does not support it. Could someone helps me
please?




如何使用NULL?你说正确的值仍未定义所以

NULL当场应该是正确的。


问候

Christian


-

Christian Kratzer ck@cksoft.de

CK Software GmbH http://www.cksoft.de/

电话:+49 7452 889 135传真:+49 7452 889 136


-------------------- -------(播出结束)---------------------------

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


Emi Lu写道:
大家好,

我有一个关于日期的问题。 &安培; "时间戳" PostgreSQL中的类型。我想
设置默认值''0000-00-00''和'0000-00-00 00:00:00"对于他们。但是,似乎PostgreSQL不支持它。有人可以帮助我吗?


PostgreSQL并不是,而且几乎肯定永远都不会支持bb作为约会。那是因为它不是一个有效的日期。你也不能存储

13.723,你好世界。或者(12,13)在日期栏中。


如果你没有有效的存储日期,你应该使用NULL。这个

存储零的业务是一个可怕的MySQL设计错误。

示例表:

T1(col1 varchar(7)not null,
col2 varchar(4)not null,
col3 date not null,
col 4 varchar(3),
主键(col1,col2,col3)


在我的设计模型中,col3必须是主要关键部分之一。由于在数据开始时
,我们不知道
col3的价值; col3的值通过GUI输入。
Hello all,

I have a question about "date" & "timestamp" types in PostgreSQL. I want
to setup the default value ''0000-00-00'' and "0000-00-00 00:00:00" for
them. However, it seems that PostgreSQL does not support it. Could
someone helps me please?
PostgreSQL doesn''t and almost certainly never will support "0000-00-00"
as a date. That''s because it isn''t a valid date. You also can''t store
13.723, "Hello world" or (12,13) in a date column either.

Where you don''t have a valid date to store you should use NULL. This
business of storing zeroes is a horrible MySQL design mistake.
The example table:

T1 (col1 varchar(7) not null,
col2 varchar(4) not null,
col3 date not null,
col 4 varchar(3),
primary key(col1, col2, col3)
)
In my design model, "col3" has to be one of the primary key part. Since
at the beginning of the data population, we do not know the value of
"col3"; values for "col3" are input throught GUI.




如果你不知道col3的价值,它就不能成为你主要的一部分

键。这是主键定义的一部分。并试图工作

周围是什么导致你在这里遇到问题。


如果你有一个初始的数据需要,那么 ; col3"

设置然后听起来你需要两个表T0与主键

(col1,col2)和T1与(col1,col2,col3)和副本从T0 => T1作为用户

供应价值。很难说不了解你的情况。


HTH

-

Richard Huxton

Archonet Ltd


---------------------------(播出结束)--- ------------------------

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



If you don''t know the value of col3, it can''t be part of your primary
key. That''s part of the definition of "primary key" and trying to work
around it is what''s causing you problems here.

If you have an initial population of data that then needs to have "col3"
set then it sounds like you need two tables T0 with primary-key
(col1,col2) and T1 with (col1,col2,col3) and copy from T0=>T1 as users
supply values. Difficult to say without knowing more about your situation.

HTH
--
Richard Huxton
Archonet Ltd

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


这篇关于如何设置默认值" 0000-00-00对于“日期”在PostgreSQL下输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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