Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.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
Postgresql 如何将默认时间戳设置为now();n天?_Postgresql - Fatal编程技术网

Postgresql 如何将默认时间戳设置为now();n天?

Postgresql 如何将默认时间戳设置为now();n天?,postgresql,Postgresql,我正在开发一个auth流,其中使用带有到期时间戳的令牌。 当用户成功登录时,将生成一个令牌并将其保存在数据库中 我知道我可以添加expires时间戳,该时间戳等于now(),但如何自动添加n小时/天?只需将其用作默认表达式: create table token ( id integer primary key, token text, expires timestamp default current_timestamp + interval '8' hour ); 只需将

我正在开发一个auth流,其中使用带有到期时间戳的令牌。 当用户成功登录时,将生成一个令牌并将其保存在数据库中


我知道我可以添加
expires
时间戳,该时间戳等于
now()
,但如何自动添加
n
小时/天?

只需将其用作默认表达式:

create table token
(
   id integer primary key,
   token text,
   expires timestamp default current_timestamp + interval '8' hour
);

只需将其用作默认表达式:

create table token
(
   id integer primary key,
   token text,
   expires timestamp default current_timestamp + interval '8' hour
);
例如:

例如:

now()+“2天”::间隔
?。。(小时/月任意)
now()+“2天”::间隔
?。。(小时/月,任意)