Postgresql 使用CDO从Postgres检索数组

Postgresql 使用CDO从Postgres检索数组,postgresql,chapel,Postgresql,Chapel,我使用下表中的IhaveaPG实例从Postgres中提取数组时出错 DROP TABLE IF EXISTS aagg; CREATE TABLE aagg (team text, name text); INSERT INTO aagg VALUES ('Wonder Pets', 'Linny'); INSERT INTO aagg VALUES ('Wonder Pets', 'Ming Ming'); INSERT INTO aagg VALUES ('Wonder Pets', '

我使用下表中的IhaveaPG实例从Postgres中提取数组时出错

DROP TABLE IF EXISTS aagg;
CREATE TABLE aagg (team text, name text);
INSERT INTO aagg VALUES ('Wonder Pets', 'Linny'); 
INSERT INTO aagg VALUES ('Wonder Pets', 'Ming Ming');
INSERT INTO aagg VALUES ('Wonder Pets', 'Tuck');
INSERT INTO aagg VALUES ('OJ Defense Team', 'F. Lee Bailey'); 
INSERT INTO aagg VALUES ('OJ Defense Team', 'Robert Shapiro');
INSERT INTO aagg VALUES ('OJ Defense Team', 'Johnny Cohchran');
我正试着用下面的礼拜仪式节目来拉它

use Postgres;

config const DB_HOST: string = "localhost";
config const DB_USER: string = "buddha";
config const DB_NAME: string = "buddha";
config const DB_PWD: string = "buddha";


var con = PgConnectionFactory(host=DB_HOST, user=DB_USER, database=DB_NAME, passwd=DB_PWD);
var cursor = con.cursor();
// Retrieve the data
const q = "SELECT team, array_agg(name) AS members FROM aagg GROUP BY team;"; 
cursor.query(q);

for row in cursor {
  writeln("Team: ", row['name'], "\tMembers: ", row['members'] );
  for member in row['members'] {
    writeln ("Special mention to ", member);
  }
}
但是循环会像中一样分解角色

Special mention to {
Special mention to "
Special mention to F
Special mention to .
Special mention to  
Special mention to L
Special mention to e
Special mention to e
Special mention to  
Special mention to B
Special mention to a
Special mention to i
Special mention to l
Special mention to e
Special mention to y
Special mention to "
如何获取此信息以识别阵列?谢谢

使用
行[“column\u name”]
行.get(“column\u name”)
时,可以将列值作为字符串获取。但是,Postgres可以使用列数组响应查询。要处理这个问题,您应该使用row.getArray(“column_name”)方法来获取Postgres数组作为字符串数组

例:

use Postgres;

config const DB_HOST: string = "localhost";
config const DB_USER: string = "buddha";
config const DB_NAME: string = "buddha";
config const DB_PWD:  string = "buddha";

var con = PgConnectionFactory( host=DB_HOST,
                               user=DB_USER,
                               database=DB_NAME,
                               passwd=DB_PWD
                               );
var cursor = con.cursor();

// Retrieve the data

const q = "SELECT team, array_agg(name) AS members FROM aagg GROUP BY team;"; 

cursor.query(q);

for row in cursor {

  writeln("Team: ", row['name'], "\tMembers: ", row['members'] );

  for member in row.getArray("members") {

    writeln ("Special mention to ", member);

  }

}