Search Postgresql Archives

Re: Associative array in Pl/PgSQL

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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



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




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux