我使用以下原始查询创建了给定表的备份:
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
表仍为空。
有人能帮我理解这里可能出现的问题吗?
答案 0 :(得分:0)
尝试DB::statement()
或DB::table('answers')->insert('...')