如何将默认时间戳设置为 now() + n 天? [英] How to set default timestamp to now() + n days?

查看:64
本文介绍了如何将默认时间戳设置为 now() + n 天?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个身份验证流程,其中使用具有到期时间戳的令牌.当用户登录成功时,会生成一个令牌并保存在数据库中.

I am developing an auth flow, where tokens with expiry timestamp are used. When a user logs in successfully, a token is generated and saved in the DB.

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

I know I can add expires timestamp that is equal to now(), but how do I add n hours/days to it automatically?

推荐答案

例如:

t=# create table t5(t timestamp default now() + '1 day'::interval);
CREATE TABLE
t=# insert into t5 default values;
INSERT 0 1
t=# select now(),t from t5;
              now              |             t
-------------------------------+----------------------------
 2018-01-26 08:05:06.641249+00 | 2018-01-27 08:04:57.035831
(1 row)

这篇关于如何将默认时间戳设置为 now() + n 天?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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