Skip to content

Array columns with NOT NULL fail on Updates #602

@glerchundi

Description

@glerchundi
Contributor

When trying to update a column of array type (in our case a StringArray one), the Update fails if a nil is provided instead of an empty slice.

This is really hard to identify beforehand because the array type is usually an alias to a slice of a base type (i.e StringArray aliases as []string) and therefore it's fairly easy to make an assignment without any type casting.

In short, the generated SQL code looks something like this against a column specified to be NOT NULL:

UPDATE table SET string_array_column = NULL WHERE ...;

I'm opening the issue to discuss how would be the best way to approach this. One possible solution that comes to my mind is to make an analogy of the database/sql types by creating Null*Array variants.

WDYT?

Activity

aarondl

aarondl commented on Sep 12, 2019

@aarondl
Owner

@glerchundi definitely I think we should remain consistent in our Null* approach instead of trying to come up with a new solution specifically for arrays.

In my opinion this is working perfectly, if you put nil in, you get an error because your intent is incorrect. The error messages may be terrible, it may be surprising, and it may be a tough thing to remember to do (meaning the ergonomics around the current behavior are awful), but it's doing the right thing I think which is not compromising your data.

If we do create a Null* for the array types, I'm not opposed to generating a nicer error message for the ArrayType when it's nil, given that it should no longer be used when nil isn't possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @aarondl@glerchundi@stephenafamo

        Issue actions

          Array columns with NOT NULL fail on Updates · Issue #602 · aarondl/sqlboiler