-
Notifications
You must be signed in to change notification settings - Fork 62
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
Postgres Grails - Storing List as JSON vs Map as JSON #50
Comments
I think it makes sense to store the objects as a list. I'm going to try and see what I can do. |
@umakot please note that your expected result storing as a list is not a valid json. The Instead of this:
The values that is stored is:
Is that ok for you? |
I mean, I'm not really sure if it's possible to query this list of jsons to get, for example, all the fieds with Please see the actual json operators: http://www.postgresql.org/docs/9.3/static/functions-json.html |
Have you consider using hstore instead json for this? |
ivan, Entire postgres functions are reasonably well developed for "arrays of objects" ( I prefer this to be list in Java/Grails code) . Also ,you are right abt "[{"label":"Work",....},{"label":"Home",....}]" (square brackets) for the array to be inserted. About your question on how to query for label="Work". I have created the following sql. You can run thru and see how it works.
Step2: (insert 3 records)
step 3: Query for records with 'label' = 'Work' ( 2 records, bcos one record has label= 'Office')
step 4: Query for records with 'label' = 'Home' |
At the moment is not possible to define a I'll keep you posted. |
Thanks. Not sure, but even an Array of "objects" is also workable I guess. |
I sent a PR to grails yesterday and it was accepted. In the next 2.3.x and 2.4.x versions the |
I've finally found some time to work on this feature. I have a working version compatible with Grails 3. I'll try to cleanup the code an publish a new version with the feature in the next days. |
Hello ilopmar, I am having a similar issue. wondering if this feature is released yet? Thank you, |
Hi @ilopmar You mentioned you were working on this feature. Did you get a chance to finalise it? |
Sorry, I didn't finish the feature and I'm not working on this anymore. If you send a PR with the feature I'll review it and release a new version. |
Hi,
I want to create a "List of Objects" as JSON in postgres. The 3.2.0 version of grails-postgresql-extensions allows to do the same with "Map of Objects ". Objects are simple POJO
I have created the attached git to draw upon the example on what I want to do https://github.com/umakot/testpost.git
In this example Person Domain object has list of addresses and I want to store those addresses in JSON on postgres. In the Domain object, I want tot define it as "List". However I cannot have the list map to JSON in Static Mapping of domain class. Where as If I define the addresses as Map, it allows me to store as JSON in postgres.
The problem with storing addresses as "Map" instead of "List" is that querying it is not easy in hibernate and psql command prompt.
Please let me know if I am missing something or if there is a different way to think/do about it.
here is the difference in storage on json
Storing Map as JSON
Storing List as JSON (here the map key is not there and easier to query.)
The text was updated successfully, but these errors were encountered: