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基本的に、テーブルから 、 answercreated_atおよびの 3 つのフィールドをコピーするだけで済みますupdated_at。他のものには新しい値を割り当てる必要があるため、上記のステートメントがあります。

このコード フラグメントを実行しても、エラーは発生しません。それでも、挿入は行われません。answersテーブルは空のままです。

ここで何が間違っているのかを理解してくれる人はいますか?

4

1 に答える 1