我目前正在尝试使用这里找到的解决方案,但我似乎无法更改用户列的类型 date
至 integer
.
当我尝试时:
ALTER TABLE users ALTER COLUMN password_reset_expires TYPE integer;
我得到这个错误:
ERROR: column "password_reset_expires" cannot be cast automatically to type integer
HINT: You might need to specify "USING password_reset_expires::integer".
当我尝试时:
ALTER TABLE users ALTER COLUMN password_reset_expires TYPE integer
USING (password_reset_expires::integer);
错误告诉我:
ERROR: cannot cast type date to integer
LINE 1: ...expires TYPE integer USING (password_reset_expires::integer)...
我的表定义:
Table "public.users"
Column | Type | Collation | Nullable | Default
------------------------+------------------------+-----------+----------+-----------------------------------
id | bigint | | not null | nextval('users_id_seq'::regclass)
name | character varying(20) | | not null |
email | character varying(100) | | not null |
password | character varying(500) | | not null |
password_changed_at | date | | |
password_reset_token | character varying(300) | | |
password_reset_expires | date | | |
Indexes:
"users_pkey" PRIMARY KEY, btree (id)
Referenced by:
TABLE "tokens" CONSTRAINT "tokens_token_pk_fkey" FOREIGN KEY (fk_users_id) REFERENCES users(id)
以下是我的一个用户对象:
{
id: '59',
name: 'visitor',
email: 'visitor',
password: '$2b$10$0UGgdRUlXFYeQfk5Nv/vXe9khdzyyOqsTiFGyNXLfEDuOFAt0xc1G',
password_changed_at: null,
password_reset_token: null,
password_reset_expires: null
}
1条答案
按热度按时间jxct1oxe1#
基本上,使用sql标准函数
EXTRACT()
. 您的意见:我要存储的内容
password_reset_expires
以及password_changed_at
是1594329364292这样的数字吗... 表示要将自unix epoch 1970-01-01 00:00:00以来的毫秒数存储为整数值。但这超出了类型的范围
integer
(签名)int4
),最多允许2^31-1=2147483647。在撰写本文时,自纪元以来已经过了1594335691272毫秒。将秒存储在
integer
列:或将毫秒存储在
bigint
柱(签名)
int8
,最多允许2^63-1=9223372036854775807):