xref: /sqlite-3.40.0/test/upsert3.test (revision 5e3a6ebf)
15015c9b5Sdrh# 2018-04-17
25015c9b5Sdrh#
35015c9b5Sdrh# The author disclaims copyright to this source code.  In place of
45015c9b5Sdrh# a legal notice, here is a blessing:
55015c9b5Sdrh#
65015c9b5Sdrh#    May you do good and not evil.
75015c9b5Sdrh#    May you find forgiveness for yourself and forgive others.
85015c9b5Sdrh#    May you share freely, never taking more than you give.
95015c9b5Sdrh#
105015c9b5Sdrh#***********************************************************************
115015c9b5Sdrh#
125015c9b5Sdrh# Test cases for UPSERT
135015c9b5Sdrh#
145015c9b5Sdrh
155015c9b5Sdrhset testdir [file dirname $argv0]
165015c9b5Sdrhsource $testdir/tester.tcl
175015c9b5Sdrhset testprefix zipfile
185015c9b5Sdrh
195015c9b5Sdrhdo_execsql_test upsert3-100 {
205015c9b5Sdrh  CREATE TABLE t1(k int, v text);
215015c9b5Sdrh  CREATE UNIQUE INDEX x1 ON t1(k, v);
225015c9b5Sdrh} {}
235015c9b5Sdrhdo_catchsql_test upsert3-110 {
245015c9b5Sdrh  INSERT INTO t1 VALUES(0,'abcdefghij')
255015c9b5Sdrh     ON CONFLICT(k) DO NOTHING;
265015c9b5Sdrh} {1 {ON CONFLICT clause does not match any PRIMARY KEY or UNIQUE constraint}}
275015c9b5Sdrhdo_catchsql_test upsert3-120 {
285015c9b5Sdrh  INSERT INTO t1 VALUES(0,'abcdefghij')
295015c9b5Sdrh     ON CONFLICT(v) DO NOTHING;
305015c9b5Sdrh} {1 {ON CONFLICT clause does not match any PRIMARY KEY or UNIQUE constraint}}
315015c9b5Sdrh
325015c9b5Sdrhdo_execsql_test upsert3-130 {
335015c9b5Sdrh  INSERT INTO t1 VALUES(0, 'abcdefghij')
345015c9b5Sdrh      ON CONFLICT(k,v) DO NOTHING;
355015c9b5Sdrh  SELECT * FROM t1;
365015c9b5Sdrh} {0 abcdefghij}
375015c9b5Sdrhdo_execsql_test upsert3-140 {
385015c9b5Sdrh  INSERT INTO t1 VALUES(0, 'abcdefghij')
395015c9b5Sdrh      ON CONFLICT(v,k) DO NOTHING;
405015c9b5Sdrh  SELECT * FROM t1;
415015c9b5Sdrh} {0 abcdefghij}
425015c9b5Sdrh
435015c9b5Sdrhdo_execsql_test upsert3-200 {
445015c9b5Sdrh  CREATE TABLE excluded(a INT, b INT, c INT DEFAULT 0);
455015c9b5Sdrh  CREATE UNIQUE INDEX excludedab ON excluded(a,b);
465015c9b5Sdrh  INSERT INTO excluded(a,b) VALUES(1,2),(1,2),(3,4),(1,2),(5,6),(3,4)
475015c9b5Sdrh    ON CONFLICT(b,a) DO UPDATE SET c=excluded.c+1;
485015c9b5Sdrh  SELECT *, 'x' FROM excluded ORDER BY a;
495015c9b5Sdrh} {1 2 2 x 3 4 1 x 5 6 0 x}
505015c9b5Sdrhdo_execsql_test upsert3-210 {
51*5e3a6ebfSdrh  INSERT INTO excluded AS base(a,b,c) VALUES(1,2,8),(1,2,3)
525015c9b5Sdrh    ON CONFLICT(b,a) DO UPDATE SET c=excluded.c+1 WHERE base.c<excluded.c;
535015c9b5Sdrh  SELECT *, 'x' FROM excluded ORDER BY a;
545015c9b5Sdrh} {1 2 9 x 3 4 1 x 5 6 0 x}
555015c9b5Sdrh
565015c9b5Sdrh
575015c9b5Sdrh
585015c9b5Sdrhfinish_test
59