DB :: insert - 不返回错误,但是没有从语句中插入结果

时间:2016-03-25 05:34:33

标签: laravel eloquent laravel-query-builder

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

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表格中的三个字段 - answercreated_atupdated_at。其他人必须分配新值,因此上述陈述。

当我运行此代码片段时,我没有错误。然而,插入不会发生。 answers表仍为空。

有人能帮我理解这里可能出现的问题吗?

1 个答案:

答案 0 :(得分:0)

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