Reputation: 9700
I have a query which returns a table of keys and values, thus:
key | value
-----+------------------
a | 3.73333333333333
b | 2.3
c | 2.76666666666667
I'd like to convert it into an hstore:
hstore
-----------------------
'a' => '3.73333333333333', 'b' => '2.3', 'c' => '2.76666666666667'
There are hstore-producing functions that take text, a pair of texts, or even a pair of arrays, but none that take a table in this fashion.
How is this done?
Upvotes: 3
Views: 1026
Reputation: 838156
Haven't tested, but would this work?
SELECT hstore(array_agg(key ORDER BY key), array_agg(value ORDER BY key))
FROM yourtable
Upvotes: 4