Ho un array json memorizzato nel mio database postgres. JSON simile a questa:Come trasformare un array json in righe in postgres
[
{
"operation": "U",
"taxCode": "1000",
"description": "iva description",
"tax": "12"
},
{
"operation": "U",
"taxCode": "1001",
"description": "iva description",
"tax": "12"
},
{
"operation": "U",
"taxCode": "1002",
"description": "iva description",
"tax": "12"
}
]
ora ho bisogno di selezionare l'array in modo che ogni elemento è in una diversa riga del risultato della query. Quindi l'istruzione SELECT effettuo deve restituire i dati in questo modo:
data
--------------------------------------------------------------------------------------
{ "operation": "U", "taxCode": "1000", "description": "iva description", "tax":"12"}
{ "operation": "U", "taxCode": "1001", "description": "iva description", "tax":"12"}
{ "operation": "U", "taxCode": "1002", "description": "iva description", "tax":"12"}
Ho provato ad utilizzare la funzione
SELECT unnest(json_data::json)
FROM my_table
unnest()
ma non accetta il tipo jsonb
'unnest()' è per i tipi di array di PostgreSQL. [Uso] (http://www.postgresql.org/docs/current/static/functions-json.html) 'json_array_elements (json)' (9.3+), 'jsonb_array_elements (jsonb)' (9.4+) o 'json [b] _array_elements_text (json [b]) '(9.4+) – pozs
Grazie. Se rispondi alla domanda, posso accettarlo. – k4ppa