lavina
4 months ago

Raw input into DB

Posted 4 months ago by lavina

Hello,

I've been attempting to mass insert rows into a table, and update if it already exists. This functionality is not supported by laravel(only for single row inserts as far as i've found), thus i am trying to write a raw insert, but it seems i am using the wrong sql sintax:

DB::insert('INSERT INTO
        products (name, description, created_at, updated_at)
        VALUES
        (\'name\',\'desc\',\'2020-02-19 09:03:45\',\'2020-02-19 09:03:45\'),
    (\'name\',\'desc\',\'2020-02-19 09:03:46\',\'2020-02-19 09:03:46\')
        ON DUPLICATE KEY UPDATE updated_at=\'2020-02-19 09:03:47\';
        ');

And duplicate key seems to only work on primary keys, which i let the table generate, thus each input is unique, how can i specify a different column to check duplicates for?

Please sign in or create an account to participate in this conversation.