1

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?

3
  • 5
    Hstore supports directly construction from a text[] based on documentation. Did you try just hstore(array)? Commented Jan 24, 2018 at 5:56
  • 1
    hstore('{"a", 10000, "b", 20000}'::text[]) works just fine Commented Jan 24, 2018 at 7:46
  • Thanks all - my bad. If you lodge this as answer, I will tag it as correct answer. Commented Jan 30, 2018 at 0:24

1 Answer 1

2

As Sami mentioned, just use:

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

Output:

           hstore
----------------------------
 "a"=>"10000", "b"=>"20000"
(1 row)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.