PostgeSQL: Arrays Data Type with PHP

Posted by ArchJ on Stack Overflow See other posts from Stack Overflow or by ArchJ
Published on 2012-04-03T04:19:17Z Indexed on 2012/04/03 11:30 UTC
Read the original article Hit count: 237

Filed under:
|

I'm working on PostgeSQL with PHP and I know that PosrgeSQL allow columns of a table to be defined as arrays.

So let's say I have a table like this:

CREATE TABLE sal_emp (
    a            text ARRAY,
    b            text ARRAY,
    c            text ARRAY,
);

These are my arrays:

$a = array(aa,bb,cc);
$b = array(dd,dd,aa);
$c = array(bb,ff,ee);

and I want to insert them into respective column each like this:

     a     |     b      |      c     
-----------+------------+------------
{aa,bb,cc} | {dd,dd,aa} |  {bb,ff,ee}

Can I insert it this way?

$a = implode(',', $a);
$b = implode(',', $b);
$c = implode(',', $c);
$a = array('a' => $a, 'b' => $b, 'c' => $c);
pg_insert($dbconn, 'table', $a);

Or is there a better way to achieve the same result?

© Stack Overflow or respective owner

Related posts about arrays

Related posts about postgresql