2017-01-27 6 views
0

Ich finde keine Lösung, um ein Array von Json-Objekt mit Rotverschiebung abzufragen. Für jede Reihe, habe ich eine Reihe von json Objekt in einer Säule wie folgt gespeichert:JSON Redshift SQL - Iteration durch Array von JSON

[{'a':x,'b':y,'type':z},{'a':x,'b':y,'type':w},{'a':x,'b':y,'type':z},{a:x,b:y,type:z}]

Für jede Reihe, möchte ich die Anzahl der ‚Typ‘ z-Objekt in einer neuen Spalte extrahieren. Wer hätte eine Idee?

Vielen Dank,

Nicolas

+0

Schauen Sie sich diese Frage ... die frei belegbare Funktions Bits könnte hier sinnvoll sein: http://stackoverflow.com/questions/41979669/expand-a-json-data-into-new-columns-in -a-generische-Mode-in-Rotverschiebung – systemjack

Antwort

1

Ich habe diese Syntax, um eine Schleife durch json-Arrays in Rotverschiebung Bereichen eingesetzt.

CREATE TEMP TABLE seq 
(i int); INSERT INTO seq VALUES(0),(1),(2),(3),(4),(5),(6),(7),(8); 

SELECT distinct 
json_extract_path_text(json_extract_array_element_text(yourfieldname, seq.i),'type') as type 
FROM yourtablename, seq AS seq 
--- arman why is this less than the array 
WHERE seq.i < JSON_ARRAY_LENGTH(yourfieldname) 

; 

DROP TABLE seq;