Update triggers do not fire on `INSERT INTO...ON DUPLICATE KEY UPDATE...`
- Dominant language
- Go
- Stars
- 24.4k
- Forks
- 873
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 108
Description
Repro.
As you can see insert triggers fire just fine.
```
$ dolt init --fun
Successfully initialized dolt data repository.
$ dolt sql -q "create table t (pk int primary key, c1 int, ts timestamp)"
$ cat < in.csv
pk,c1
0,0
1,1
EOF
$ dolt sql -q "CREATE TRIGGER trigger1
BEFORE INSERT ON t
FOR EACH ROW
SET NEW.ts = CURRENT_TIMESTAMP();"
$ dolt sql -q "insert into t(pk,c1) values (5,5)";
Query OK, 1 row affected (0.00 sec)
$ dolt sql -q "select * from t"
+----+----+---------------------+
| pk | c1 | ts |
+----+----+---------------------+
| 5 | 5 | 2023-05-11 15:55:39 |
+----+----+---------------------+
$ dolt table import -u t in.csv
Warning: There are fewer columns in the import file's schema than the table's schema.
If unintentional, check for any typos in the import file's header.
Rows Processed: 2, Additions: 2, Modifications: 0, Had No Effect: 0
Import completed successfully.
$ dolt sql -q "select * from t"
+----+----+---------------------+
| pk | c1 | ts |
+----+----+---------------------+
| 0 | 0 | 2023-05-11 15:56:21 |
| 1 | 1 | 2023-05-11 15:56:21 |
| 5 | 5 | 2023-05-11 15:55:39 |
+----+----+---------------------+
$
```
Now if I add an additional update trigger and make a new CSV, the update trigger is not fired on import:
```
$ dolt sql -q "CREATE TRIGGER trigger2
BEFORE UPDATE ON t
FOR EACH ROW
SET NEW.ts = CURRENT_TIMESTAMP();"
$ dolt table import -u t in.csv
Warning: There are fewer columns in the import file's schema than the table's schema.
If unintentional, check for any typos in the import file's header.
Rows Processed: 2, Additions: 0, Modifications: 0, Had No Effect: 2
Import completed successfully.
$ dolt sql -q "select * from t"
+----+----+---------------------+
| pk | c1 | ts |
+----+----+---------------------+
| 0 | 0 | 2023-05-11 15:56:21 |
| 1 | 1 | 2023-05-11 15:56:21 |
| 5 | 5 | 2023-05-11 15:55:39 |
+----+----+---------------------+
$ cat < in.csv
pk,c1
0,1
1,2
EOF
$ dolt table import -u t in.csv
Warning: There are fewer columns in the import file's schema than the table's schema.
If unintentional, check for any typos in the import file's header.
Rows Processed: 2, Additions: 0, Modifications: 2, Had No Effect: 0
Import completed successfully.
$ dolt sql -q "select * from t"
+----+----+---------------------+
| pk | c1 | ts |
+----+----+---------------------+
| 0 | 1 | 2023-05-11 15:56:21 |
| 1 | 2 | 2023-05-11 15:56:21 |
| 5 | 5 | 2023-05-11 15:55:39 |
+----+----+---------------------+
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.