cockroachdb / cockroachdb/cockroach
Adding a size limit to bytes.
- Dominant language
- Go
- Stars
- 32.5k
- Forks
- 4.1k
- PR merge metrics
- PR metrics pending
Description
I'm trying to set a size limit for a ```BYTES``` column in a ```CREATE``` statement. The documentation [here](https://www.cockroachlabs.com/docs/v23.2/bytes#size) shows a code example in the "Warning:" box, which suggests that this is possible, but it uses a ```STRING``` datatype:
```
To add a size limit using [CREATE TABLE](https://www.cockroachlabs.com/docs/v23.2/create-table):
CREATE TABLE name (first STRING(100), last STRING(100));
```
While the example works fine, trying the same with ```BYTES``` throws an error:
```
testdb=> CREATE TABLE name (first BYTES(100), last BYTES(100));
ERROR: at or near "(": syntax error
DETAIL: source SQL:
CREATE TABLE name (first BYTES(100), last BYTES(100))
^
HINT: try \h CREATE TABLE
```
Is it possible to use a size limit for ```BYTES```?
My goal is a space-efficient representation for constant unsigned integer types with 16 and 32 bits. It would be possible to translate these types into ```INT2``` and ```INT4```, but I would prefer to have the untranslated value in the database. An ```INT8``` looks like the best workaround at the moment. Maybe this is the best solution at all as I'm not sure if a ```BYTES(2)``` or ```BYTES(4)``` would be really smaller than an ```INT8```.
**Environment:**
- CockroachDB version: v23.2.0
- Server OS: Ubuntu 22.04.3 LT
- Client app: psql
Jira issue: CRDB-36052
Contributor guide
Assessment
This issue has not been assessed yet.