aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/varlena.c
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2011-12-23 08:40:25 -0500
committerRobert Haas <rhaas@postgresql.org>2011-12-23 08:40:25 -0500
commitd5448c7d31b5af66a809e6580bae9bd31448bfa7 (patch)
tree6e10ff9bd80f51aedad9abf3c037195f284a1254 /src/backend/utils/adt/varlena.c
parent0510b62d91151b9d8c1fe1aa15c9cf3ffe9bf25b (diff)
downloadpostgresql-d5448c7d31b5af66a809e6580bae9bd31448bfa7.tar.gz
postgresql-d5448c7d31b5af66a809e6580bae9bd31448bfa7.zip
Add bytea_agg, parallel to string_agg.
Pavel Stehule
Diffstat (limited to 'src/backend/utils/adt/varlena.c')
-rw-r--r--src/backend/utils/adt/varlena.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/backend/utils/adt/varlena.c b/src/backend/utils/adt/varlena.c
index 95893386aae..d66ba065400 100644
--- a/src/backend/utils/adt/varlena.c
+++ b/src/backend/utils/adt/varlena.c
@@ -396,6 +396,53 @@ byteasend(PG_FUNCTION_ARGS)
PG_RETURN_BYTEA_P(vlena);
}
+Datum
+bytea_agg_transfn(PG_FUNCTION_ARGS)
+{
+ StringInfo state;
+
+ state = PG_ARGISNULL(0) ? NULL : (StringInfo) PG_GETARG_POINTER(0);
+
+ /* Append the value unless null. */
+ if (!PG_ARGISNULL(1))
+ {
+ bytea *value = PG_GETARG_BYTEA_PP(1);
+
+ if (state == NULL)
+ state = makeStringAggState(fcinfo);
+
+ appendBinaryStringInfo(state, VARDATA_ANY(value), VARSIZE_ANY_EXHDR(value));
+ }
+
+ /*
+ * The transition type for bytea_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)
+{
+ StringInfo state;
+
+ /* cannot be called directly because of internal-type argument */
+ Assert(AggCheckCallContext(fcinfo, NULL));
+
+ state = PG_ARGISNULL(0) ? NULL : (StringInfo) PG_GETARG_POINTER(0);
+
+ if (state != NULL)
+ {
+ bytea *result;
+
+ result = (bytea *) palloc(state->len + VARHDRSZ);
+ SET_VARSIZE(result, state->len + VARHDRSZ);
+ memcpy(VARDATA(result), state->data, state->len);
+ PG_RETURN_BYTEA_P(result);
+ }
+ else
+ PG_RETURN_NULL();
+}
/*
* textin - converts "..." to internal representation