Re: how to key/value iterate in stored function - Mailing list pgsql-general

From David Johnston
Subject Re: how to key/value iterate in stored function
Date
Msg-id 483E5688-3213-48DD-91E1-20065139CCC1@yahoo.com
Whole thread Raw
In response to Re: how to key/value iterate in stored function  ("J.V." <jvsrvcs@gmail.com>)
Responses Re: how to key/value iterate in stored function  ("J.V." <jvsrvcs@gmail.com>)
List pgsql-general

On Oct 12, 2011, at 14:43, "J.V." <jvsrvcs@gmail.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?
>
> J.V.
>
> On 10/12/2011 8:51 AM, Merlin Moncure wrote:
>> On Wed, Oct 12, 2011 at 8:46 AM, J.V.<jvsrvcs@gmail.com>  wrote:
>>> I want to create a variable that is an array or list of key/value pairs.
>>>
>>> The key would be a table name and the value would be a sql statement or a
>>> value or list of values for which I could extract to create a sql statement
>>> and execute.
>>>
>>> I have tried experimenting with various arrays, but there is no clear
>>> example or documentation.  The key and the value would be text.
>>>
>>> I want to iterate over the entire array (or list), so would need an example
>>> on that or some pointers there, if there is help.
>> use thee the hstore!
>>
>> postgres=# select * from each('a=>1,b=>2');
>>  key | value
>> -----+-------
>>  a   | 1
>>  b   | 2
>> (2 rows)
>>
>> (if you do stick with arrays, use unnest() -- it can be built for
>> older versions if you don't have it).
>>
>> merlin
>>
>
> --
> Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general

Create a custom type with two text components and use that in an array.

David J.

pgsql-general by date:

Previous
From: "J.V."
Date:
Subject: how to list or array of key value pairs
Next
From: Rich Shepard
Date:
Subject: psql died in midst of session