array_to_string(array_agg(array_to_string(array[
highlights,exceptions,inter_note,inter_status::text
,comp_note,comp_status::text,hard_note,hard_status::text]
,'|#|'::text))
,'|*|'::text) as status
By executing the above query the status
should contain 8 values separated by |#|
or |*|
. But in some cases it returns only 3, 4 or 6 values. I need to get all 8 values weather the record is empty or not.
Example:
original array:
[|#||#||#||#|Complete|#||#|Undefined|#||#|Undefined]
some cases:
[|#||#||#|PASS|#|Complete|#|Undefined|#|Undefined]
another case:
[Complete|#|Undefined|#|Undefined]
Any idea why some array elements are missing?
Best Answer
Ensure that every field has a default value by using COALESCE.
dbfiddle here