Skip to content
Advertisement

I need a query in postgres that returns the length of arrays but without taking empty values into consideration

so given the table:

They don’t have a standard and some values may come empty ( for example {Will, , }). I tried:

But I get this:

and I want it to return:

So I need something which gives me the length only of the populated fields (empty spaces like ‘ ‘) shouldn’t be counted.

Advertisement

Answer

You can remove the NULL values and then count:

For one-dimensional arrays, I find that cardinality() is convenient:

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement