William Leite Araújo escreveu: > Na verdade você não precisaria de nenhum /contrib/ para executar > essa operação. > http://www.postgresql.org/docs/8.3/interactive/sql-createaggregate.html > > Bastaria criar uma função de /agregação/ para concatenar os > valores. Um exemplo: > > *CREATE AGGREGATE* txtcat(sfunc=textcat, basetype=text,stype=text); > > *SELECT* c.name <http://c.name> as "NomeCarta", > trim(txtcat(*COALESCE*(d.name <http://d.name>||', ',''))', ') as "Cores" > *FROM* cards c *JOIN* colors_for_cards cc on( c.code= cc.cards) > *JOIN* colors d on (cc.colors = d.code)) > *GROUP BY* c.code >
Nessa linha considero mais interessante, e mais genérico, o exemplo array_accum. http://www.postgresql.org/docs/current/interactive/xaggr.html CREATE AGGREGATE array_accum (anyelement) ( sfunc = array_append, stype = anyarray, initcond = '{}' ); SELECT attrelid::regclass, array_accum(attname) FROM pg_attribute WHERE attnum > 0 AND attrelid = 'pg_tablespace'::regclass GROUP BY attrelid; attrelid | array_accum ---------------+--------------------------------------- pg_tablespace | {spcname,spcowner,spclocation,spcacl} (1 row) SELECT attrelid::regclass, array_accum(atttypid) FROM pg_attribute WHERE attnum > 0 AND attrelid = 'pg_tablespace'::regclass GROUP BY attrelid; attrelid | array_accum ---------------+----------------- pg_tablespace | {19,26,25,1034} (1 row) Osvaldo _______________________________________________ pgbr-geral mailing list [email protected] https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral
