【发布时间】:2020-07-09 21:54:13
【问题描述】:
我目前正在尝试使用找到here 的解决方案,但我似乎无法将用户列的类型从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
}
【问题讨论】:
-
请提供样本数据和期望的结果。对于给定日期,您想要什么值并不明显。
-
@GordonLinoff 刚刚在最后添加了一个用户示例。我想在
password_reset_expires和password_changed_at中存储的是这样的数字 1594329364292 -
您为什么要开始这样做?日期值应存储在
date列中,日期/时间值应存储在timestamp或timestamptz列中。不要使用愚蠢的时代来做到这一点。 blog.sql-workbench.eu/post/epoch-mania
标签: sql postgresql date types ddl