Search code examples
postgresqldata-conversionhstore

Postgres text array to hstore


I have an array of even length, with comma delimited values (not necessarily homogeneous):

'{"a", 10000, "b", 20000}'

I would like to parse this postgres array into an hstore column, associating each odd entry (index 1,3,...) as a key, and each even entry (index 2,4,...) as value. Is this possible?


Solution

  • As Sami mentioned, just use:

    SELECT hstore('{"a", 10000, "b", 20000}'::text[]);
    

    Output:

               hstore
    ----------------------------
     "a"=>"10000", "b"=>"20000"
    (1 row)