For simplicity sake, say I have a table with a single column that is just an hstore. What is the most efficient way to go about getting a unqiue list of all the keys from all rows of the hstore?
eg.
my_hstore
------------
a=>1,b=>2
b=>2,c=>3
x=>10,y=>11
y=>11,z=12
What is the most efficient way to retrieve a list/array/set containing (a,b,c,x,y,z) ?
There's always the straight forward skeys
approach:
select distinct k
from (
select skeys(my_hstore) as k
from your_table
) as dt
And if you need an array, then add an array_agg
:
select array_agg(distinct k)
from (
select skeys(my_hstore) as k
from your_table
) as dt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With