我正在尝试使用node和typescript创建一个忘记密码的界面。我想在忘记密码数据库中插入忘记密码令牌,我使用以下查询来完成此操作。基本上我使用guid作为代币并试图引用我的人员,派对和contact_details表
INSERT INTO
dbo.forgot_password_tokens
SELECT
'random_guid' as forgot_password_tokens_id,
current_timestamp as updated_at,
cd.contact_details_id,
u.users_id
FROM
dbo.users as u
inner join dbo.people as pe on pe.people_id = u.people_id
inner join dbo.parties as pa on pa.parties_id = pa.parties_id
inner join dbo.contact_details as cd on
cd.parties_id = pa.parties_id
and cd.value = 'devin@email.com'
and cd.contact_details_types_id in ('guid_for_email', 'guid_for_second_email')
这是我得到的错误
ERROR: column "updated_at" is of type timestamp with time zone but expression is of type uuid
LINE 6: cd.contact_details_id,
我不确定为什么它说updated_at收到了错误的数据,我认为current_timestamp会将它放在正确的位置
答案 0 :(得分:7)
目标表中列的顺序可能与您选择中的列顺序不匹配。这是一个非常好的示例,说明为什么始终在insert
语句中指定列列表:
INSERT INTO dbo.forgot_password_tokens
(forgot_password_tokens_id, updated_at, contact_details_id, users_id)
SELECT ...
FROM ...