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.
I know I can add
eg:
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)
Just use that as the default expression:
create table token
(
id integer primary key,
token text,
expires timestamp default current_timestamp + interval '8' hour
);