Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

array insertion: #759

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

Mikcl
Copy link

@Mikcl Mikcl commented Sep 10, 2024

array type insertion failing

A table created with a column which is an Array type does not seem to work with insertions. This PR shows a simple example of what can trigger this, (tested it manually on postgres).


Here is an error message i got on a minimal table setup:

\d people
                              Table "public.people"
   Column   |  Type  | Collation | Nullable |              Default               
------------+--------+-----------+----------+------------------------------------
 id         | bigint |           | not null | nextval('people_id_seq'::regclass)
 first_name | text   |           |          | 
 last_name  | text   |           |          | 
 names      | text[] |           |          | 
ERROR:  malformed array literal: "John" from GORM:
DETAIL:  Array value must start with "{" or dimension information.
STATEMENT:  INSERT INTO "people" ("first_name","last_name","names") VALUES ($1,$2,($3)) RETURNING "id"

GORM sent: INSERT INTO "people" ("first_name","last_name","names") VALUES ('John','Doe',('John')) RETURNING "id"


You can correct this in one way by using curly braces around the array:

The correct way to insert:

INSERT INTO "people" ("first_name", "last_name", "names") 
VALUES ('John', 'Doe', '{"John"}');

Example of failure:

INSERT INTO "people" ("first_name", "last_name", "names") 
VALUES ('John', 'Doe', '("John")');
ERROR:  malformed array literal: "("John")"
LINE 2: VALUES ('John', 'Doe', '("John")');
                               ^
DETAIL:  Array value must start with "{" or dimension information.

ps:

Since it does not work with insertions, unable to confirm whether this works for other operations, I would expect arrays to work though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant