简体   繁体   中英

query postgresql array column

I couldn't convert postgresql array to php array. Here is my array column is character varying[] and here are the values {image1,image2,image3}

$imgArry always null.

$query = "SELECT \"A\".\"id\",
                array_to_json(\"A\".images)
                 FROM 
                public.A " ;

    $rs = pg_query($db, $query) or
            die("Cannot execute query: $query\n");
    $index = 0;
    while ($row = pg_fetch_assoc($rs)) {
        $A->id = $row["id"];

        $imgArry = json_decode($row["images"]);
        $planproduct->image=$imgArry[0];

This does it.

 preg_match('/^{(.*)}$/', $row["images"], $matches);
 $imgArry=str_getcsv($matches[1]);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM