Skip to content
This repository was archived by the owner on Mar 25, 2022. It is now read-only.
This repository was archived by the owner on Mar 25, 2022. It is now read-only.

How to handle arrays as records for INSERTS and UPDATES #22

Description

@joshtwist

How would I best use pg-format to handle the insertion of arrays into columns with an array type.

Imagine a table with a column 'roles' of type text[].

To insert into that table the statement would look something like

INSERT INTO table (name, roles) VALUES ("Josh", ARRAY["role1", "role2"])
or
INSERT INTO table(name, roles) VALUES ("Josh", {"role1", "role2"})

However, when pg-format encounters an array it formats as a literal like this:

INSERT INTO table(name, roles) VALUES ("Josh", ("role1", "role2")) which is invalid. That format ("role1", "role2") works great for IN statements so clearly is the correct handling for arrays in some circumstances.

Recommendations for UPDATES and INSERTS where the value being written is an Array?

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions