Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 如何创建日期小于今天日期的属性表_Sql_Database_Postgresql_Constraints_Relational Database - Fatal编程技术网

Sql 如何创建日期小于今天日期的属性表

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

在PostgreSQL中,如何创建具有日期小于今天日期的属性的表

这就是我想做的:

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