dolthub / dolthub/dolt

Auto Increment increments despite error

Open
#3,157 2 comments 0 reactions 2 assignees Claimed by @zachmu View on GitHub
bug correctness sql
Dominant language
Go
Stars
24.4k
Forks
873
Avg merge
1d 5h
Merged PRs (30d)
108

Description

When an insertion fails, a column defined with `auto_increment` still increments the value.

Repro:
```shell
test_db> create table t (i int primary key auto_increment, j int not null);
test_db> insert into t values (0,0);
Query OK, 1 row affected
test_db> select * from t;
+---+---+
| i | j |
+---+---+
| 1 | 0 |
+---+---+
test_db> insert into t values (0, null);
column name 'j' is non-nullable but attempted to set a value of null
test_db> select * from t;
+---+---+
| i | j |
+---+---+
| 1 | 0 |
+---+---+
test_db> insert into t values (0, 0);
Query OK, 1 row affected
test_db> select * from t;
+---+---+
| i | j |
+---+---+
| 1 | 0 |
| 3 | 0 |
+---+---+
```

The resulting table should be:
```shell
mysql> select * from t;
+---+---+
| i | j |
+---+---+
| 1 | 0 |
| 2 | 0 |
+---+---+
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.