我使用以下原始查询创建了给定表的备份:
DB::statement("DROP TABLE IF EXISTS answers_bup");
DB::statement("CREATE TABLE answers_bup AS TABLE answers");
该answers
表具有以下架构:
CREATE TABLE answers
(
id uuid NOT NULL,
user_id uuid NOT NULL,
survey_id uuid NOT NULL,
question_id uuid NOT NULL,
answer character varying(255) NOT NULL,
created_at timestamp(0) without time zone NOT NULL,
updated_at timestamp(0) without time zone NOT NULL,
}
现在,为了恢复单行,从answers_bup
表到answers
表。我写了以下内容DB::insert
:
$void = DB::insert("INSERT INTO answers
SELECT
'?'::uuid AS id,
'?'::uuid AS user_id,
'?'::uuid AS survey_id,
'?'::uuid AS question_id,
answer,
created_at,
updated_at
FROM
answers_bup
WHERE
id='?'::uuid", [
$newId,
$user_id,
$survey_id,
$question_id,
$answer->id
]);
基本上,我只需要从answers_bup
表中复制三个字段-answer
和. 其他的,必须被分配新的值,因此上面的声明。created_at
updated_at
当我运行此代码片段时,我没有收到任何错误。然而,插入不会发生。answers
桌子仍然是空的。
谁能帮我理解这里可能出了什么问题?