Re: how to key/value iterate in stored function

From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: "J(dot)V(dot)" <jvsrvcs(at)gmail(dot)com>
Cc: PostgreSQL <pgsql-general(at)postgresql(dot)org>
Subject: Re: how to key/value iterate in stored function
Date: 2011-10-12 23:10:19
Message-ID: CAHyXU0x6Z4rRtybZe+L7_mJ8O1JxKV5u31pv9Y0dXmLL2F9KDQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Oct 12, 2011 at 1:43 PM, J.V. <jvsrvcs(at)gmail(dot)com> wrote:
> I tried hstore with no luck.
>
> How do I initialize the array?
>
> How do I loop through each key/value pair in a stored function to retrieve
> the key and value for each item in the list?
>
> I need a list of key value pairs.  Any options there?

it's all in the docs:
postgres=# select * from each(hstore(ARRAY['a','b'], ARRAY['1','2']));
key | value
-----+-------
a | 1
b | 2
(2 rows)

dont see what's so hard 'bout that. 9.0+ hstore is superior to the
composite type method in every way I can think of unless you are
storing explictly non text value in the type and you are not
transferring the compacted list to the client. hstore is much more
flexible in terms of getting data in/out, searching, etc. as a bonus
you have gist indexing if you need it, etc etc.

merlin

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Andy Colson 2011-10-12 23:29:22 Re: PostGIS: Approximating a house number from street address range
Previous Message Bob Hatfield 2011-10-12 23:03:28 Re: Are file system level differential/incremental backups possible?