If I query this :
SELECT DISTINCT class_low
FROM groups NATURAL JOIN species
WHERE type ~~ 'faune'
AND class_high ~~ 'Arachnides'
AND (class_middle ~~ 'Araignées' OR class_middle IS NULL)
AND (class_low ~~ '%' OR class_low IS NULL);
I get :
class_low
---------------------
Dictynidés
Linyphiidés
Sparassidés
Metidés
Thomisidés
Dolomedidés
Pisauridés
Araignées sauteuses
Araneidés
Lycosidés
Atypidés
Pholcidés
Ségestriidés
Tetragnathidés
Miturgidés
Agelenidés
Notice the NULL value (it's not a empty varchar).
now if I query like that :
SELECT array_to_string(array_agg(DISTINCT class_low), ',')
FROM groups NATURAL JOIN species
WHERE type ~~ 'faune'
AND class_high ~~ 'Arachnides'
AND (class_middle ~~ 'Araignées' OR class_middle IS NULL)
AND (class_low ~~ '%' OR class_low IS NULL);
I get :
array_to_string
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Agelenidés,Araignées sauteuses,Araneidés,Atypidés,Dictynidés,Dolomedidés,Linyphiidés,Lycosidés,Metidés,Miturgidés,Pholcidés,Pisauridés,Ségestriidés,Sparassidés,Tetragnathidés,Thomisidés
The NULL value is not inserted.
Is there any way to include it ? I mean having something like :
...,,... (just a double colon)