inserting array initialized with zeros violates not-null constraint of schema
- Dominant language
- Go
- Stars
- 14.3k
- Forks
- 1.1k
- Avg merge
- 6d 9h
- Merged PRs (30d)
- 11
Description
In the schema I'm using there is a table called _vectors_ which has a row _vector_.
The row _vector_ has as constraint that it cannot be null.
I have no problems inserting any array into this table except when i try to insert an array initialized with all zeros:
```
Working code:
a := [768]float64{}
a[0] = 1
err := database.Insert(a)
=> Insert OK
```
```
Not working:
a := [768]float64{}
a[0] = 0
err := database.Insert(a)
=> ERROR: null value in column "vector" of relation "vectors" violates not-null constraint (SQLSTATE 23502)
```
Why is this happening? is it a bug of pgx? is it a postgres convention to treat arrays initialized with zeros as null?
Contributor guide
Research direction
Start at the database.Insert call shown in the report and trace how the zero-valued Go array is encoded and sent to PostgreSQL. Reproduce both insertion examples, then determine whether the driver sends a NULL value or an array containing zeros; done means the cause is identified and the all-zero array is handled consistently.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, postgresql
- Domain
- database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100