how to list or array of key value pairs

Started by J.V.over 14 years ago4 messagesgeneral
Jump to latest
#1J.V.
jvsrvcs@gmail.com

I need to rephrase this because of some confusion as to what I was
looking for.

I want to create and initialize a list or array of key/value pairs.
Then I want to iterate through this list (or array) retrieving each
key/value for use in a sql statement.

I want to do this in a stored function.

that's all

any ideas?

J.V.

#2Sergey Konoplev
gray.ru@gmail.com
In reply to: J.V. (#1)
Re: how to list or array of key value pairs

Probably this will help you
http://www.postgresql.org/docs/current/interactive/hstore.html

ps. Look at the each() function.

On 12 October 2011 22:45, J.V. <jvsrvcs@gmail.com> wrote:

I need to rephrase this because of some confusion as to what I was looking
for.

I want to create and initialize a list or array of key/value pairs.  Then I
want to iterate through this list (or array) retrieving each key/value for
use in a sql statement.

I want to do this in a stored function.

that's all

any ideas?

J.V.

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

--
Sergey Konoplev

Blog: http://gray-hemp.blogspot.com /
Linkedin: http://ru.linkedin.com/in/grayhemp /
JID/GTalk: gray.ru@gmail.com / Skype: gray-hemp

#3J.V.
jvsrvcs@gmail.com
In reply to: Sergey Konoplev (#2)
Re: how to list or array of key value pairs

Yes, I have seen this before.

But I need an array of key/value pairs (key is string, value is string)
and I need to iterate through the array accessing both the key and the
value.

I look at this page and it does not translate very well into what I need
to do. If there are any specific examples out there, it would be
greatly appreciated.

Sincerely,

J.V.

Show quoted text

On 10/13/2011 2:18 AM, Sergey Konoplev wrote:

Probably this will help you
http://www.postgresql.org/docs/current/interactive/hstore.html

ps. Look at the each() function.

On 12 October 2011 22:45, J.V.<jvsrvcs@gmail.com> wrote:

I need to rephrase this because of some confusion as to what I was looking
for.

I want to create and initialize a list or array of key/value pairs. Then I
want to iterate through this list (or array) retrieving each key/value for
use in a sql statement.

I want to do this in a stored function.

that's all

any ideas?

J.V.

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#4Merlin Moncure
mmoncure@gmail.com
In reply to: J.V. (#3)
Re: how to list or array of key value pairs

On Fri, Oct 14, 2011 at 3:22 PM, J.V. <jvsrvcs@gmail.com> wrote:

Yes, I have seen this before.

But I need an array of key/value pairs (key is string, value is string) and
I need to iterate through the array accessing both the key and the value.

I look at this page and it does not translate very well into what I need to
do.  If there are any specific examples out there, it would be greatly
appreciated.

you keep getting the same answer because as you described your problem
it does *exactly* what you want to do. so, either you are not
describing the problem well or you are not understanding us:
postgres=# select * from each('a=>1,b=>2');
key | value
-----+-------
a | 1
b | 2
(2 rows)

can be dropped directly into plgsql

for record_variable in select * from each('a=>1,b=>2')
loop
<do stuff>
end loop;

etc. What's the issue?

merlin