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

Getting issues while using JSONSlice for Postgres [] #266

Open
venky-connectwise opened this issue Aug 6, 2024 · 3 comments
Open

Getting issues while using JSONSlice for Postgres [] #266

venky-connectwise opened this issue Aug 6, 2024 · 3 comments
Assignees

Comments

@venky-connectwise
Copy link

Your Question

How can I use JSONSlice for JSON[] fields with gorm, I have used the library but getting an error while inserting the data. The Table model struct is attached below.

The document you expected this should be explained

https://go.dev/play/p/aEEKW7fUa72

I am getting issue when the arrays are empty in the database layer.

UTC [268] ERROR: malformed array literal: "null"
postgres-1 | 2024-08-06 15:18:34.167 UTC [268] DETAIL: Array value must start with "{" or dimension information.

Expected answer

@alingse
Copy link
Contributor

alingse commented Sep 5, 2024

postgres array type format is like '{ val1 delim val2 delim ... }', It's not a JSON style data.

see https://www.postgresql.org/docs/current/arrays.html

@venky-connectwise
Copy link
Author

postgres array type format is like '{ val1 delim val2 delim ... }', It's not a JSON style data.

see https://www.postgresql.org/docs/current/arrays.html

I m not passing any data, that should be valid right, if you see my message carefully, i have mentioned that I passing empty field, shouldn't the library handle that?

@alingse
Copy link
Contributor

alingse commented Sep 9, 2024

@venky-connectwise the JSONSlice now is for JSON type column , It is decode the field value as a slice, not the pg's JSON[] filed type. it's first JSON and then use as slice, it can be

json <-> []string
json <-> []struct
json <-> []int

the value should be json style

["1a", "2b", "3c"]

what you want is

JSON[] <-> []any

the pg's array style is like

{"1a", "2b", "3c"}

it can't decode by json.Unmarshal

Maybe we can support the pg's Array by add another generic type ?

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

No branches or pull requests

3 participants