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

bug: postgres driver tries to insert slices and arrays as records, and fails #668

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sleddev
Copy link

@sleddev sleddev commented Dec 10, 2023

Explain your user case and expected results

When inserting go arrays or slices in a GORM model, the generated SQL uses them as records, so the insert fails.

For example:

type Test struct {
	Data []float64 `gorm:"type:float8[]"`
}

test := Test{Data: []float64{8, 4, 2, 1, 0.5}}
DB.Create(&test)

gives the SQL:

INSERT INTO "tests" ("data") VALUES ((8,4,2,1,0.5))

And I get the error ERROR: column "data" is of type double precision[] but expression is of type record (SQLSTATE 42804)

Instead, the SQL should be:

INSERT INTO "tests" ("data") VALUES ('{8,4,2,1,0.5}')

or

INSERT INTO "tests" ("data") VALUES (ARRAY [8,4,2,1,0.5])

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