Re: Associative array in Pl/PgSQL

Поиск
Список
Период
Сортировка
От Darren Duncan
Тема Re: Associative array in Pl/PgSQL
Дата
Msg-id 5185BC90.5070702@darrenduncan.net
обсуждение исходный текст
Ответ на Associative array in Pl/PgSQL  (Karel Riveron Escobar <kescobar@estudiantes.uci.cu>)
Список pgsql-general
On 2013.05.04 4:40 PM, Karel Riveron Escobar wrote:
> Hello everyone,
>
> I have a problem with Pl/PgSQL function. I need to pass it as parameter an
> associative array. I have no idea how to do that. Can somebody help me?
>
> To be more specific, I have an associative array in PHP. Something like this:
>
> array(
>       'name' => 'Robert',
>       'age' => 24,
>       'teachers' => array(
>                                     array('name'=>'Sean'),
>                                     array('name'=>'Megan')
>                              )
> );
>
> And, I need work with it into a Pl/PgSQL function. How can I do this?

The answer to your question depends on a number of factors about the structure
of your associative array.

If the structure is heterogeneous, where each element might be a different data
type, and if the keys of your array are all text analogous to attribute names,
then a SQL tuple/row is the most direct analogy, so use some ROW type with one
attribute per associative array element.

Conversely, if the structure is homogeneous, where all elements have the same
key types and same value types, then a binary/2-attribute/column relation/table
is the most direct analogy, so then use a TABLE(key text,value whatever) type.

 From your example though, it looks like a ROW is definitely what you want.

-- Darren Duncan



В списке pgsql-general по дате отправления:

Предыдущее
От: Jasen Betts
Дата:
Сообщение: Re: Associative array in Pl/PgSQL
Следующее
От: Steve Rogerson
Дата:
Сообщение: Composite fields and the query planner