Sql 如何创建日期小于今天日期的属性表
在PostgreSQL中,如何创建具有日期小于今天日期的属性的表 这就是我想做的:Sql 如何创建日期小于今天日期的属性表,sql,database,postgresql,constraints,relational-database,Sql,Database,Postgresql,Constraints,Relational Database,在PostgreSQL中,如何创建具有日期小于今天日期的属性的表 这就是我想做的: CREATE TABLE Player( dob DATE CHECK(dob < today's date) NOT NULL /*other attributes and constraints omitted*/ ); 创建桌面播放器( dob日期检查(dob
CREATE TABLE Player(
dob DATE CHECK(dob < today's date) NOT NULL
/*other attributes and constraints omitted*/
);
创建桌面播放器(
dob日期检查(dob<今天的日期)不为空
/*省略了其他属性和约束*/
);
这可能吗
提前谢谢你 这个答案要归功于@Gordon Linoff。 他建议我使用PostgreSQL提供的
now()
函数
now()
函数返回当前日期和时间
有关更多信息,请参阅
我的结果表如下所示:
CREATE TABLE Player(
dob DATE CHECK(dob < now()) NOT NULL
/*other attributes and constraints omitted*/
);
创建桌面播放器(
dob日期检查(dob
执行以下操作:
你对
check(dob
有问题吗?没有,我对check(dob
没有任何问题这正是我想要的。谢谢@戈登林诺菲特错了。正确的版本是dob
Ahh是的,我想current_date应该是正确的,因为它返回当前日期。但是now()函数将返回当前日期和时间。如果我使用now()而不是current_date,会有什么不同吗@请检查我的答案
check (dob < current_date)
select
current_date,
current_date::timestamp,
now(),
current_date < now(),
current_date < current_date;
date | timestamp | now | ?column? | ?column?
------------+---------------------+-------------------------------+----------+----------
2017-04-04 | 2017-04-04 00:00:00 | 2017-04-04 11:54:39.703732+00 | t | f