2016-03-25 6 views
0

sonucu:DB :: insert - hayır hata verir, henüz ekler ben şu ham sorguları kullanarak belirli bir tablonun yedeğini oluşturduk açıklamada

DB::statement("DROP TABLE IF EXISTS answers_bup"); 
DB::statement("CREATE TABLE answers_bup AS TABLE answers"); 

answers tablosu aşağıdaki şema vardır:

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, 
} 

Şimdi, tek bir satırı geri yüklemek için answers_bup tablosundan answers tablosuna. answer, created_at ve updated_at - Sadece answers_bup tablodan üç alana taşımanız gerekir, Temelde

$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 
]); 

: Ben DB::insert aşağıdaki yazdım. Diğerleri, yeni değerler atanmalıdır, dolayısıyla yukarıdaki ifade.

Bu kod parçasını çalıştırdığımda hata alıyorum. Yine de, insert olmaz. answers tablosu boş kalır.

Burada neyin yanlış olabileceğini anlamama yardımcı olabilir misiniz?

cevap

0

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

İlgili konular