Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd5448c7

Browse files
committed
Add bytea_agg, parallel to string_agg.
Pavel Stehule
1 parent0510b62 commitd5448c7

File tree

8 files changed

+116
-1
lines changed

8 files changed

+116
-1
lines changed

‎doc/src/sgml/func.sgml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10908,6 +10908,24 @@ SELECT NULLIF(value, '(none)') ...
1090810908
<entry>true if at least one input value is true, otherwise false</entry>
1090910909
</row>
1091010910

10911+
<row>
10912+
<entry>
10913+
<indexterm>
10914+
<primary>bytea_agg</primary>
10915+
</indexterm>
10916+
<function>
10917+
bytea_agg(<replaceable class="parameter">expression</replaceable>)
10918+
</function>
10919+
</entry>
10920+
<entry>
10921+
<type>bytea</type>
10922+
</entry>
10923+
<entry>
10924+
<type>bytea</type>
10925+
</entry>
10926+
<entry>input values concatenated into a bytea</entry>
10927+
</row>
10928+
1091110929
<row>
1091210930
<entry>
1091310931
<indexterm>

‎src/backend/utils/adt/varlena.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,53 @@ byteasend(PG_FUNCTION_ARGS)
396396
PG_RETURN_BYTEA_P(vlena);
397397
}
398398

399+
Datum
400+
bytea_agg_transfn(PG_FUNCTION_ARGS)
401+
{
402+
StringInfostate;
403+
404+
state=PG_ARGISNULL(0) ?NULL : (StringInfo)PG_GETARG_POINTER(0);
405+
406+
/* Append the value unless null. */
407+
if (!PG_ARGISNULL(1))
408+
{
409+
bytea*value=PG_GETARG_BYTEA_PP(1);
410+
411+
if (state==NULL)
412+
state=makeStringAggState(fcinfo);
413+
414+
appendBinaryStringInfo(state,VARDATA_ANY(value),VARSIZE_ANY_EXHDR(value));
415+
}
416+
417+
/*
418+
* The transition type for bytea_agg() is declared to be "internal",
419+
* which is a pass-by-value type the same size as a pointer.
420+
*/
421+
PG_RETURN_POINTER(state);
422+
}
423+
424+
Datum
425+
bytea_agg_finalfn(PG_FUNCTION_ARGS)
426+
{
427+
StringInfostate;
428+
429+
/* cannot be called directly because of internal-type argument */
430+
Assert(AggCheckCallContext(fcinfo,NULL));
431+
432+
state=PG_ARGISNULL(0) ?NULL : (StringInfo)PG_GETARG_POINTER(0);
433+
434+
if (state!=NULL)
435+
{
436+
bytea*result;
437+
438+
result= (bytea*)palloc(state->len+VARHDRSZ);
439+
SET_VARSIZE(result,state->len+VARHDRSZ);
440+
memcpy(VARDATA(result),state->data,state->len);
441+
PG_RETURN_BYTEA_P(result);
442+
}
443+
else
444+
PG_RETURN_NULL();
445+
}
399446

400447
/*
401448
*textin- converts "..." to internal representation

‎src/include/catalog/catversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/*yyyymmddN */
56-
#defineCATALOG_VERSION_NO201112221
56+
#defineCATALOG_VERSION_NO201112231
5757

5858
#endif

‎src/include/catalog/pg_aggregate.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ DATA(insert ( 2335array_agg_transfnarray_agg_finalfn02281_null_ ));
226226
/* text */
227227
DATA(insert (3538string_agg_transfnstring_agg_finalfn02281_null_ ));
228228

229+
/* bytea */
230+
DATA(insert (3545bytea_agg_transfnbytea_agg_finalfn02281_null_ ));
231+
229232
/*
230233
* prototypes for functions in pg_aggregate.c
231234
*/

‎src/include/catalog/pg_proc.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2403,12 +2403,19 @@ DATA(insert OID = 2816 ( float8_covar_sampPGNSP PGUID 12 1 0 0 0 f f f t f i
24032403
DESCR("aggregate final function");
24042404
DATA(insertOID=2817 (float8_corrPGNSPPGUID121000ffftfi10701"1022"_null__null__null__null_float8_corr_null__null__null_ ));
24052405
DESCR("aggregate final function");
2406+
24062407
DATA(insertOID=3535 (string_agg_transfnPGNSPPGUID121000fffffi302281"2281 25 25"_null__null__null__null_string_agg_transfn_null__null__null_ ));
24072408
DESCR("aggregate transition function");
24082409
DATA(insertOID=3536 (string_agg_finalfnPGNSPPGUID121000fffffi1025"2281"_null__null__null__null_string_agg_finalfn_null__null__null_ ));
24092410
DESCR("aggregate final function");
24102411
DATA(insertOID=3538 (string_aggPGNSPPGUID121000tffffi2025"25 25"_null__null__null__null_aggregate_dummy_null__null__null_ ));
24112412
DESCR("concatenate aggregate input into a string");
2413+
DATA(insertOID=3543 (bytea_agg_transfnPGNSPPGUID121000fffffi202281"2281 17"_null__null__null__null_bytea_agg_transfn_null__null__null_ ));
2414+
DESCR("aggregate transition function");
2415+
DATA(insertOID=3544 (bytea_agg_finalfnPGNSPPGUID121000fffffi1017"2281"_null__null__null__null_bytea_agg_finalfn_null__null__null_ ));
2416+
DESCR("aggregate final function");
2417+
DATA(insertOID=3545 (bytea_aggPGNSPPGUID121000tffffi1017"17"_null__null__null__null_aggregate_dummy_null__null__null_ ));
2418+
DESCR("concatenate aggregate input into a bytea");
24122419

24132420
/* To ASCII conversion */
24142421
DATA(insertOID=1845 (to_asciiPGNSPPGUID121000ffftfi1025"25"_null__null__null__null_to_ascii_default_null__null__null_ ));

‎src/include/utils/builtins.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,8 @@ extern Datum unknownsend(PG_FUNCTION_ARGS);
769769

770770
externDatumpg_column_size(PG_FUNCTION_ARGS);
771771

772+
externDatumbytea_agg_transfn(PG_FUNCTION_ARGS);
773+
externDatumbytea_agg_finalfn(PG_FUNCTION_ARGS);
772774
externDatumstring_agg_transfn(PG_FUNCTION_ARGS);
773775
externDatumstring_agg_finalfn(PG_FUNCTION_ARGS);
774776

‎src/test/regress/expected/aggregates.out

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,3 +1061,26 @@ select string_agg(distinct f1::text, ',' order by f1::text) from varchar_tbl; -
10611061
a,ab,abcd
10621062
(1 row)
10631063

1064+
-- bytea_agg tests
1065+
create table bytea_test_table(v bytea);
1066+
select bytea_agg(v) from bytea_test_table;
1067+
bytea_agg
1068+
-----------
1069+
1070+
(1 row)
1071+
1072+
insert into bytea_test_table values(decode('ff','hex'));
1073+
select bytea_agg(v) from bytea_test_table;
1074+
bytea_agg
1075+
-----------
1076+
\xff
1077+
(1 row)
1078+
1079+
insert into bytea_test_table values(decode('aa','hex'));
1080+
select bytea_agg(v) from bytea_test_table;
1081+
bytea_agg
1082+
-----------
1083+
\xffaa
1084+
(1 row)
1085+
1086+
drop table bytea_test_table;

‎src/test/regress/sql/aggregates.sql

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,3 +416,18 @@ select string_agg(distinct f1, ',' order by f1) from varchar_tbl; -- ok
416416
select string_agg(distinct f1::text,','order by f1)from varchar_tbl;-- not ok
417417
select string_agg(distinct f1,','order by f1::text)from varchar_tbl;-- not ok
418418
select string_agg(distinct f1::text,','order by f1::text)from varchar_tbl;-- ok
419+
420+
-- bytea_agg tests
421+
createtablebytea_test_table(vbytea);
422+
423+
select bytea_agg(v)from bytea_test_table;
424+
425+
insert into bytea_test_tablevalues(decode('ff','hex'));
426+
427+
select bytea_agg(v)from bytea_test_table;
428+
429+
insert into bytea_test_tablevalues(decode('aa','hex'));
430+
431+
select bytea_agg(v)from bytea_test_table;
432+
433+
droptable bytea_test_table;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp