我从 plpgsql 得到一个如下所示的数组:
[0:2]={
"(ab023500-ceef-41d6-af33-635964dbffde,Koen,\"\",Schmeets,{koen@heizoo.com},31631205427},\"{\"\"Test categorie\"\"}\",{ff0000})",
"(384cb1e9-58b9-4bdf-9da6-eb3d9355471b,Marc,\"\",Vrijhof,{},{},\"{\"\"Test categorie\"\"}\",{ff0000})",
"(9c19ec5c-6b95-456a-af6f-c3388835b780,Michael,\"\",\"Baas ;)\",{},{}, \"{\"\"Subcategorie test\"\",\"\"Test categorie\"\"}\",\"{NULL,ff0000}\")"}
我已经构建了自己的解释器来获取 Python 列表中的数组,但它似乎不是防故障的。有人知道如何在 Python 中解析这个数组吗?
编辑
unnest()
使我可以使用以下功能获得一个不错的数组:
CREATE FUNCTION array_to_json_string(in_varchararray character varying[])
RETURNS character varying LANGUAGE plpythonu AS
$_$
import cjson
plan = plpy.prepare("SELECT * FROM unnest($1)", ["varchar[]"])
rv = plpy.execute(plan, [in_varchararray])
retList = []
for r in rv:
retList .append(r["unnest"])
return cjson.encode(retList)
$_$;
虽然......它很慢!
有人知道如何将 plpgsql 数组转换为逗号分隔值吗?