cockroachdb / cockroachdb/cockroach
Column with SERIAL[] type doesn't generate default values
- Dominant language
- Go
- Stars
- 32.5k
- Forks
- 4.1k
- PR merge metrics
- PR metrics pending
Description
**Describe the problem**
The point of the [SERIAL](https://www.cockroachlabs.com/docs/v22.2/serial) data type is that it auto-generates values if not specificed, but if you create a table with an array of `SERIAL`s, no default values are built:
```sql
CREATE TABLE increment (a SERIAL[] PRIMARY KEY);
INSERT INTO increment DEFAULT VALUES;
ERROR: null value in column "a" violates not-null constraint
```
Without the primary key, this would just insert a null value.
Postgres errors out this case:
```sql
postgres=# CREATE TABLE increment (a SERIAL[]);
ERROR: array of serial is not implemented
```
In fact, Postgres does not even treat SERIAL as a data type:
```sql
postgres=# SELECT 1::SERIAL;
ERROR: type "serial" does not exist
```
Whereas CRDB does:
```sql
root@localhost:26257/db> SELECT 1::SERIAL;
int8
--------
1
(1 row)
```
Postgres seems to treat it more like syntactic sugar for auto-increment on an integer column in table DDL, but the underlying data type is just integer.
**Expected behavior**
We should probably error out creation of tables with `SERIAL[]` columns, like Postgres, and maybe even remove it as a type you can CAST to, also like Postgres.
**Environment:**
- CockroachDB version: All versions, v23.1 and below
- Server OS: All
Jira issue: CRDB-27566
Contributor guide
Assessment
This issue has not been assessed yet.