right within each byte; for example bit 0 is the least significant bit of
the first byte, and bit 15 is the most significant bit of the second byte.
</para>
+
+ <para>
+ See also the aggregate function <function>string_agg</function> in
+ <xref linkend="functions-aggregate">.
+ </para>
</sect1>
<entry>true if at least one input value is true, otherwise false</entry>
</row>
- <row>
- <entry>
- <indexterm>
- <primary>bytea_agg</primary>
- </indexterm>
- <function>
- bytea_agg(<replaceable class="parameter">expression</replaceable>)
- </function>
- </entry>
- <entry>
- <type>bytea</type>
- </entry>
- <entry>
- <type>bytea</type>
- </entry>
- <entry>input values concatenated into a bytea</entry>
- </row>
-
<row>
<entry>
<indexterm>
</function>
</entry>
<entry>
- <type>text</type>, <type>text</type>
+ (<type>text</type>, <type>text</type>) or (<type>bytea</type>, <type>bytea</type>)
</entry>
<entry>
- <type>text</type>
+ same as argument types
</entry>
<entry>input values concatenated into a string, separated by delimiter</entry>
</row>
}
Datum
-bytea_agg_transfn(PG_FUNCTION_ARGS)
+bytea_string_agg_transfn(PG_FUNCTION_ARGS)
{
StringInfo state;
{
bytea *value = PG_GETARG_BYTEA_PP(1);
+ /* On the first time through, we ignore the delimiter. */
if (state == NULL)
state = makeStringAggState(fcinfo);
+ else if (!PG_ARGISNULL(2))
+ {
+ bytea *delim = PG_GETARG_BYTEA_PP(2);
+
+ appendBinaryStringInfo(state, VARDATA_ANY(delim), VARSIZE_ANY_EXHDR(delim));
+ }
appendBinaryStringInfo(state, VARDATA_ANY(value), VARSIZE_ANY_EXHDR(value));
}
/*
- * The transition type for bytea_agg() is declared to be "internal",
+ * The transition type for string_agg() is declared to be "internal",
* which is a pass-by-value type the same size as a pointer.
*/
PG_RETURN_POINTER(state);
}
Datum
-bytea_agg_finalfn(PG_FUNCTION_ARGS)
+bytea_string_agg_finalfn(PG_FUNCTION_ARGS)
{
StringInfo state;
*/
/* yyyymmddN */
-#define CATALOG_VERSION_NO 201204053
+#define CATALOG_VERSION_NO 201204131
#endif
DATA(insert ( 3538 string_agg_transfn string_agg_finalfn 0 2281 _null_ ));
/* bytea */
-DATA(insert ( 3545 bytea_agg_transfn bytea_agg_finalfn 0 2281 _null_ ));
+DATA(insert ( 3545 bytea_string_agg_transfn bytea_string_agg_finalfn 0 2281 _null_ ));
/*
* prototypes for functions in pg_aggregate.c
DESCR("aggregate final function");
DATA(insert OID = 3538 ( string_agg PGNSP PGUID 12 1 0 0 0 t f f f f f i 2 0 25 "25 25" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ ));
DESCR("concatenate aggregate input into a string");
-DATA(insert OID = 3543 ( bytea_agg_transfn PGNSP PGUID 12 1 0 0 0 f f f f f f i 2 0 2281 "2281 17" _null_ _null_ _null_ _null_ bytea_agg_transfn _null_ _null_ _null_ ));
+DATA(insert OID = 3543 ( bytea_string_agg_transfn PGNSP PGUID 12 1 0 0 0 f f f f f f i 3 0 2281 "2281 17 17" _null_ _null_ _null_ _null_ bytea_string_agg_transfn _null_ _null_ _null_ ));
DESCR("aggregate transition function");
-DATA(insert OID = 3544 ( bytea_agg_finalfn PGNSP PGUID 12 1 0 0 0 f f f f f f i 1 0 17 "2281" _null_ _null_ _null_ _null_ bytea_agg_finalfn _null_ _null_ _null_ ));
+DATA(insert OID = 3544 ( bytea_string_agg_finalfn PGNSP PGUID 12 1 0 0 0 f f f f f f i 1 0 17 "2281" _null_ _null_ _null_ _null_ bytea_string_agg_finalfn _null_ _null_ _null_ ));
DESCR("aggregate final function");
-DATA(insert OID = 3545 ( bytea_agg PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 17 "17" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ ));
+DATA(insert OID = 3545 ( string_agg PGNSP PGUID 12 1 0 0 0 t f f f f f i 2 0 17 "17 17" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ ));
DESCR("concatenate aggregate input into a bytea");
/* To ASCII conversion */
extern Datum pg_column_size(PG_FUNCTION_ARGS);
-extern Datum bytea_agg_transfn(PG_FUNCTION_ARGS);
-extern Datum bytea_agg_finalfn(PG_FUNCTION_ARGS);
+extern Datum bytea_string_agg_transfn(PG_FUNCTION_ARGS);
+extern Datum bytea_string_agg_finalfn(PG_FUNCTION_ARGS);
extern Datum string_agg_transfn(PG_FUNCTION_ARGS);
extern Datum string_agg_finalfn(PG_FUNCTION_ARGS);
a,ab,abcd
(1 row)
--- bytea_agg tests
+-- string_agg bytea tests
create table bytea_test_table(v bytea);
-select bytea_agg(v) from bytea_test_table;
- bytea_agg
------------
+select string_agg(v, '') from bytea_test_table;
+ string_agg
+------------
(1 row)
insert into bytea_test_table values(decode('ff','hex'));
-select bytea_agg(v) from bytea_test_table;
- bytea_agg
------------
+select string_agg(v, '') from bytea_test_table;
+ string_agg
+------------
\xff
(1 row)
insert into bytea_test_table values(decode('aa','hex'));
-select bytea_agg(v) from bytea_test_table;
- bytea_agg
------------
+select string_agg(v, '') from bytea_test_table;
+ string_agg
+------------
\xffaa
(1 row)
+select string_agg(v, NULL) from bytea_test_table;
+ string_agg
+------------
+ \xffaa
+(1 row)
+
+select string_agg(v, decode('ee', 'hex')) from bytea_test_table;
+ string_agg
+------------
+ \xffeeaa
+(1 row)
+
drop table bytea_test_table;
select string_agg(distinct f1, ',' order by f1::text) from varchar_tbl; -- not ok
select string_agg(distinct f1::text, ',' order by f1::text) from varchar_tbl; -- ok
--- bytea_agg tests
+-- string_agg bytea tests
create table bytea_test_table(v bytea);
-select bytea_agg(v) from bytea_test_table;
+select string_agg(v, '') from bytea_test_table;
insert into bytea_test_table values(decode('ff','hex'));
-select bytea_agg(v) from bytea_test_table;
+select string_agg(v, '') from bytea_test_table;
insert into bytea_test_table values(decode('aa','hex'));
-select bytea_agg(v) from bytea_test_table;
+select string_agg(v, '') from bytea_test_table;
+select string_agg(v, NULL) from bytea_test_table;
+select string_agg(v, decode('ee', 'hex')) from bytea_test_table;
drop table bytea_test_table;