次の生のクエリを使用して、特定のテーブルのバックアップを作成しました。
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
およびの 3 つのフィールドをコピーするだけで済みますupdated_at
。他のものには新しい値を割り当てる必要があるため、上記のステートメントがあります。
このコード フラグメントを実行しても、エラーは発生しません。それでも、挿入は行われません。answers
テーブルは空のままです。
ここで何が間違っているのかを理解してくれる人はいますか?