I have a table
Visitor: (id, signup_up, sessions, email, custom_fields)
Where custom_fields
is an jsonb array of JSON objects of the form
CustomField: ( field, value )
example: (domain, www.somedomain.com)
I want to take the signed_up, sessions, email
columns and their values, and the CustomField
json objects inside the custom_fields
array, and merge them into a 3rd field called data
using the same CustomField
structure, ie. each entry has the form field: value
.
EXAMPLE
Given these rows
id | sessions | email | custom_fields
---------------------------------------------------------------
1 | 3 | test@gmail.com [{ field: domain, value: "www.hello.com" }, { field: type, value: "Customer" }]
---------------------------------------------------------------
2 | 5 | another@gmail.com [{ field: domain, value: "www.other.com" }, { field: type, value: "Customer" }]
I'd like to get
id | fields
-----------------------
1 | [{sessions: 3, email: test@gmail.com, domain: "www.hello.com", type: "Customer"}]
----------------------
2 | [{sessions: 5, email: another@gmail.com, domain: "www.other.com", type: "Customer"}]
Any idea on how this can be accomplished?
Any help is much appreciated