Reputation: 268
I would like to do a query to retrieve a key-value data structure without putting the burden on the code.
For example, if I have the following query:
SELECT id, nome FROM articolo
is there a way in mariaDB to throw this data into a key-value data structure so you don't do it from code and do it directly from query? Something like:
SELECT {id: nome} FROM articolo
Thanks in advance
Upvotes: 0
Views: 286
Reputation: 781058
You can use the JSON functions.
This creates an object for each row:
SELECT JSON_OBJECT(id, nome) FROM articolo;
If you want all the values in a single object, use:
SELECT JSON_OBJECTAGG(id, nome) FROM articolo
Upvotes: 2