I have created a backup of a given table using the following raw queries:
DB::statement("DROP TABLE IF EXISTS answers_bup");
DB::statement("CREATE TABLE answers_bup AS TABLE answers");
The answers table has the following schema:
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,
}
Now, in order to restore a single row, from the answers_bup table to the answers table. I wrote the following 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
]);
Basically, I only need to copy over three fields from the answers_bup table - answer, created_at and updated_at. The others, have to be assigned new values, hence the above statement.
When I run this code fragment, I get no errors. Yet, the insert does not happen. The answers table remains empty.
Could anyone help me understand what might be wrong here?
PS: I am working with a Postgres database v9.1