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

Commitc0cc526

Browse files
committed
Rename bytea_agg to string_agg and add delimiter argument
Per mailing list discussion, we would like to keep the bytea functionsparallel to the text functions, so rename bytea_agg to string_agg,which already exists for text.Also, to satisfy the rule that we don't want aggregate functions ofthe same name with a different number of arguments, add a delimiterargument, just like string_agg for text already has.
1 parent64e1309 commitc0cc526

File tree

8 files changed

+52
-44
lines changed

8 files changed

+52
-44
lines changed

‎doc/src/sgml/func.sgml

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3160,6 +3160,11 @@
31603160
right within each byte; for example bit 0 is the least significant bit of
31613161
the first byte, and bit 15 is the most significant bit of the second byte.
31623162
</para>
3163+
3164+
<para>
3165+
See also the aggregate function <function>string_agg</function> in
3166+
<xref linkend="functions-aggregate">.
3167+
</para>
31633168
</sect1>
31643169

31653170

@@ -10962,24 +10967,6 @@ SELECT NULLIF(value, '(none)') ...
1096210967
<entry>true if at least one input value is true, otherwise false</entry>
1096310968
</row>
1096410969

10965-
<row>
10966-
<entry>
10967-
<indexterm>
10968-
<primary>bytea_agg</primary>
10969-
</indexterm>
10970-
<function>
10971-
bytea_agg(<replaceable class="parameter">expression</replaceable>)
10972-
</function>
10973-
</entry>
10974-
<entry>
10975-
<type>bytea</type>
10976-
</entry>
10977-
<entry>
10978-
<type>bytea</type>
10979-
</entry>
10980-
<entry>input values concatenated into a bytea</entry>
10981-
</row>
10982-
1098310970
<row>
1098410971
<entry>
1098510972
<indexterm>
@@ -11061,10 +11048,10 @@ SELECT NULLIF(value, '(none)') ...
1106111048
</function>
1106211049
</entry>
1106311050
<entry>
11064-
<type>text</type>, <type>text</type>
11051+
(<type>text</type>, <type>text</type>) or (<type>bytea</type>, <type>bytea</type>)
1106511052
</entry>
1106611053
<entry>
11067-
<type>text</type>
11054+
same as argument types
1106811055
</entry>
1106911056
<entry>input values concatenated into a string, separated by delimiter</entry>
1107011057
</row>

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ byteasend(PG_FUNCTION_ARGS)
397397
}
398398

399399
Datum
400-
bytea_agg_transfn(PG_FUNCTION_ARGS)
400+
bytea_string_agg_transfn(PG_FUNCTION_ARGS)
401401
{
402402
StringInfostate;
403403

@@ -408,21 +408,28 @@ bytea_agg_transfn(PG_FUNCTION_ARGS)
408408
{
409409
bytea*value=PG_GETARG_BYTEA_PP(1);
410410

411+
/* On the first time through, we ignore the delimiter. */
411412
if (state==NULL)
412413
state=makeStringAggState(fcinfo);
414+
elseif (!PG_ARGISNULL(2))
415+
{
416+
bytea*delim=PG_GETARG_BYTEA_PP(2);
417+
418+
appendBinaryStringInfo(state,VARDATA_ANY(delim),VARSIZE_ANY_EXHDR(delim));
419+
}
413420

414421
appendBinaryStringInfo(state,VARDATA_ANY(value),VARSIZE_ANY_EXHDR(value));
415422
}
416423

417424
/*
418-
* The transition type forbytea_agg() is declared to be "internal",
425+
* The transition type forstring_agg() is declared to be "internal",
419426
* which is a pass-by-value type the same size as a pointer.
420427
*/
421428
PG_RETURN_POINTER(state);
422429
}
423430

424431
Datum
425-
bytea_agg_finalfn(PG_FUNCTION_ARGS)
432+
bytea_string_agg_finalfn(PG_FUNCTION_ARGS)
426433
{
427434
StringInfostate;
428435

‎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_NO201204053
56+
#defineCATALOG_VERSION_NO201204131
5757

5858
#endif

‎src/include/catalog/pg_aggregate.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ DATA(insert ( 2335array_agg_transfnarray_agg_finalfn02281_null_ ));
229229
DATA(insert (3538string_agg_transfnstring_agg_finalfn02281_null_ ));
230230

231231
/* bytea */
232-
DATA(insert (3545bytea_agg_transfnbytea_agg_finalfn02281_null_ ));
232+
DATA(insert (3545bytea_string_agg_transfnbytea_string_agg_finalfn02281_null_ ));
233233

234234
/*
235235
* prototypes for functions in pg_aggregate.c

‎src/include/catalog/pg_proc.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2433,11 +2433,11 @@ DATA(insert OID = 3536 ( string_agg_finalfnPGNSP PGUID 12 1 0 0 0 f f f f f f
24332433
DESCR("aggregate final function");
24342434
DATA(insertOID=3538 (string_aggPGNSPPGUID121000tfffffi2025"25 25"_null__null__null__null_aggregate_dummy_null__null__null_ ));
24352435
DESCR("concatenate aggregate input into a string");
2436-
DATA(insertOID=3543 (bytea_agg_transfnPGNSPPGUID121000ffffffi202281"2281 17"_null__null__null__null_bytea_agg_transfn_null__null__null_ ));
2436+
DATA(insertOID=3543 (bytea_string_agg_transfnPGNSPPGUID121000ffffffi302281"2281 17 17"_null__null__null__null_bytea_string_agg_transfn_null__null__null_ ));
24372437
DESCR("aggregate transition function");
2438-
DATA(insertOID=3544 (bytea_agg_finalfnPGNSPPGUID121000ffffffi1017"2281"_null__null__null__null_bytea_agg_finalfn_null__null__null_ ));
2438+
DATA(insertOID=3544 (bytea_string_agg_finalfnPGNSPPGUID121000ffffffi1017"2281"_null__null__null__null_bytea_string_agg_finalfn_null__null__null_ ));
24392439
DESCR("aggregate final function");
2440-
DATA(insertOID=3545 (bytea_aggPGNSPPGUID121000tfffffi1017"17"_null__null__null__null_aggregate_dummy_null__null__null_ ));
2440+
DATA(insertOID=3545 (string_aggPGNSPPGUID121000tfffffi2017"1717"_null__null__null__null_aggregate_dummy_null__null__null_ ));
24412441
DESCR("concatenate aggregate input into a bytea");
24422442

24432443
/* To ASCII conversion */

‎src/include/utils/builtins.h

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

772772
externDatumpg_column_size(PG_FUNCTION_ARGS);
773773

774-
externDatumbytea_agg_transfn(PG_FUNCTION_ARGS);
775-
externDatumbytea_agg_finalfn(PG_FUNCTION_ARGS);
774+
externDatumbytea_string_agg_transfn(PG_FUNCTION_ARGS);
775+
externDatumbytea_string_agg_finalfn(PG_FUNCTION_ARGS);
776776
externDatumstring_agg_transfn(PG_FUNCTION_ARGS);
777777
externDatumstring_agg_finalfn(PG_FUNCTION_ARGS);
778778

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

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,26 +1061,38 @@ 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
1064+
--string_agg bytea tests
10651065
create table bytea_test_table(v bytea);
1066-
selectbytea_agg(v) from bytea_test_table;
1067-
bytea_agg
1068-
-----------
1066+
selectstring_agg(v, '') from bytea_test_table;
1067+
string_agg
1068+
------------
10691069

10701070
(1 row)
10711071

10721072
insert into bytea_test_table values(decode('ff','hex'));
1073-
selectbytea_agg(v) from bytea_test_table;
1074-
bytea_agg
1075-
-----------
1073+
selectstring_agg(v, '') from bytea_test_table;
1074+
string_agg
1075+
------------
10761076
\xff
10771077
(1 row)
10781078

10791079
insert into bytea_test_table values(decode('aa','hex'));
1080-
selectbytea_agg(v) from bytea_test_table;
1081-
bytea_agg
1082-
-----------
1080+
selectstring_agg(v, '') from bytea_test_table;
1081+
string_agg
1082+
------------
10831083
\xffaa
10841084
(1 row)
10851085

1086+
select string_agg(v, NULL) from bytea_test_table;
1087+
string_agg
1088+
------------
1089+
\xffaa
1090+
(1 row)
1091+
1092+
select string_agg(v, decode('ee', 'hex')) from bytea_test_table;
1093+
string_agg
1094+
------------
1095+
\xffeeaa
1096+
(1 row)
1097+
10861098
drop table bytea_test_table;

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -417,17 +417,19 @@ select string_agg(distinct f1::text, ',' order by f1) from varchar_tbl; -- not
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
419419

420-
--bytea_agg tests
420+
--string_agg bytea tests
421421
createtablebytea_test_table(vbytea);
422422

423-
selectbytea_agg(v)from bytea_test_table;
423+
selectstring_agg(v,'')from bytea_test_table;
424424

425425
insert into bytea_test_tablevalues(decode('ff','hex'));
426426

427-
selectbytea_agg(v)from bytea_test_table;
427+
selectstring_agg(v,'')from bytea_test_table;
428428

429429
insert into bytea_test_tablevalues(decode('aa','hex'));
430430

431-
select bytea_agg(v)from bytea_test_table;
431+
select string_agg(v,'')from bytea_test_table;
432+
select string_agg(v,NULL)from bytea_test_table;
433+
select string_agg(v, decode('ee','hex'))from bytea_test_table;
432434

433435
droptable bytea_test_table;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp