sqlite - How to get INSERT OR IGNORE to work

前端 未结 2 1738
执念已碎
执念已碎 2020-11-29 03:00

I\'m trying to insert data into a table. I would like to insert the row if the column doesn\'t have the data already - regardless of the other columns.

CREAT         


        
2条回答
  •  北荒
    北荒 (楼主)
    2020-11-29 03:27

    That would only work for the primary key field or unique constraints:

    The optional conflict-clause allows the specification of an alternative constraint conflict resolution algorithm to use during this one INSERT command.

    Further:

    The ON CONFLICT clause applies to UNIQUE and NOT NULL constraints (and to PRIMARY KEY constraints which for the purposes of this section are the same thing as UNIQUE constraints). The ON CONFLICT algorithm does not apply to FOREIGN KEY constraints. There are five conflict resolution algorithm choices: ROLLBACK, ABORT, FAIL, IGNORE, and REPLACE. The default conflict resolution algorithm is ABORT.

提交回复
热议问题