0

我使用以下原始查询创建了给定表的备份:

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_atupdated_at

当我运行此代码片段时,我没有收到任何错误。然而,插入不会发生。answers桌子仍然是空的。

谁能帮我理解这里可能出了什么问题?

4

1 回答 1

0

尝试DB::statement(),或DB::table('answers')->insert('...')

于 2016-03-25T09:59:14.680 回答