Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
d5448c7d
Commit
d5448c7d
authored
Dec 23, 2011
by
Robert Haas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add bytea_agg, parallel to string_agg.
Pavel Stehule
parent
0510b62d
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
116 additions
and
1 deletion
+116
-1
doc/src/sgml/func.sgml
doc/src/sgml/func.sgml
+18
-0
src/backend/utils/adt/varlena.c
src/backend/utils/adt/varlena.c
+47
-0
src/include/catalog/catversion.h
src/include/catalog/catversion.h
+1
-1
src/include/catalog/pg_aggregate.h
src/include/catalog/pg_aggregate.h
+3
-0
src/include/catalog/pg_proc.h
src/include/catalog/pg_proc.h
+7
-0
src/include/utils/builtins.h
src/include/utils/builtins.h
+2
-0
src/test/regress/expected/aggregates.out
src/test/regress/expected/aggregates.out
+23
-0
src/test/regress/sql/aggregates.sql
src/test/regress/sql/aggregates.sql
+15
-0
No files found.
doc/src/sgml/func.sgml
View file @
d5448c7d
...
@@ -10908,6 +10908,24 @@ SELECT NULLIF(value, '(none)') ...
...
@@ -10908,6 +10908,24 @@ SELECT NULLIF(value, '(none)') ...
<entry>
true if at least one input value is true, otherwise false
</entry>
<entry>
true if at least one input value is true, otherwise false
</entry>
</row>
</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>
<row>
<entry>
<entry>
<indexterm>
<indexterm>
...
...
src/backend/utils/adt/varlena.c
View file @
d5448c7d
...
@@ -396,6 +396,53 @@ byteasend(PG_FUNCTION_ARGS)
...
@@ -396,6 +396,53 @@ byteasend(PG_FUNCTION_ARGS)
PG_RETURN_BYTEA_P
(
vlena
);
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
* textin - converts "..." to internal representation
...
...
src/include/catalog/catversion.h
View file @
d5448c7d
...
@@ -53,6 +53,6 @@
...
@@ -53,6 +53,6 @@
*/
*/
/* yyyymmddN */
/* yyyymmddN */
#define CATALOG_VERSION_NO 2011122
2
1
#define CATALOG_VERSION_NO 2011122
3
1
#endif
#endif
src/include/catalog/pg_aggregate.h
View file @
d5448c7d
...
@@ -226,6 +226,9 @@ DATA(insert ( 2335 array_agg_transfn array_agg_finalfn 0 2281 _null_ ));
...
@@ -226,6 +226,9 @@ DATA(insert ( 2335 array_agg_transfn array_agg_finalfn 0 2281 _null_ ));
/* text */
/* text */
DATA
(
insert
(
3538
string_agg_transfn
string_agg_finalfn
0
2281
_null_
));
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_
));
/*
/*
* prototypes for functions in pg_aggregate.c
* prototypes for functions in pg_aggregate.c
*/
*/
...
...
src/include/catalog/pg_proc.h
View file @
d5448c7d
...
@@ -2403,12 +2403,19 @@ DATA(insert OID = 2816 ( float8_covar_samp PGNSP PGUID 12 1 0 0 0 f f f t f i
...
@@ -2403,12 +2403,19 @@ DATA(insert OID = 2816 ( float8_covar_samp PGNSP PGUID 12 1 0 0 0 f f f t f i
DESCR
(
"aggregate final function"
);
DESCR
(
"aggregate final function"
);
DATA
(
insert
OID
=
2817
(
float8_corr
PGNSP
PGUID
12
1
0
0
0
f
f
f
t
f
i
1
0
701
"1022"
_null_
_null_
_null_
_null_
float8_corr
_null_
_null_
_null_
));
DATA
(
insert
OID
=
2817
(
float8_corr
PGNSP
PGUID
12
1
0
0
0
f
f
f
t
f
i
1
0
701
"1022"
_null_
_null_
_null_
_null_
float8_corr
_null_
_null_
_null_
));
DESCR
(
"aggregate final function"
);
DESCR
(
"aggregate final function"
);
DATA
(
insert
OID
=
3535
(
string_agg_transfn
PGNSP
PGUID
12
1
0
0
0
f
f
f
f
f
i
3
0
2281
"2281 25 25"
_null_
_null_
_null_
_null_
string_agg_transfn
_null_
_null_
_null_
));
DATA
(
insert
OID
=
3535
(
string_agg_transfn
PGNSP
PGUID
12
1
0
0
0
f
f
f
f
f
i
3
0
2281
"2281 25 25"
_null_
_null_
_null_
_null_
string_agg_transfn
_null_
_null_
_null_
));
DESCR
(
"aggregate transition function"
);
DESCR
(
"aggregate transition function"
);
DATA
(
insert
OID
=
3536
(
string_agg_finalfn
PGNSP
PGUID
12
1
0
0
0
f
f
f
f
f
i
1
0
25
"2281"
_null_
_null_
_null_
_null_
string_agg_finalfn
_null_
_null_
_null_
));
DATA
(
insert
OID
=
3536
(
string_agg_finalfn
PGNSP
PGUID
12
1
0
0
0
f
f
f
f
f
i
1
0
25
"2281"
_null_
_null_
_null_
_null_
string_agg_finalfn
_null_
_null_
_null_
));
DESCR
(
"aggregate final function"
);
DESCR
(
"aggregate final function"
);
DATA
(
insert
OID
=
3538
(
string_agg
PGNSP
PGUID
12
1
0
0
0
t
f
f
f
f
i
2
0
25
"25 25"
_null_
_null_
_null_
_null_
aggregate_dummy
_null_
_null_
_null_
));
DATA
(
insert
OID
=
3538
(
string_agg
PGNSP
PGUID
12
1
0
0
0
t
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"
);
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
i
2
0
2281
"2281 17"
_null_
_null_
_null_
_null_
bytea_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
i
1
0
17
"2281"
_null_
_null_
_null_
_null_
bytea_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
i
1
0
17
"17"
_null_
_null_
_null_
_null_
aggregate_dummy
_null_
_null_
_null_
));
DESCR
(
"concatenate aggregate input into a bytea"
);
/* To ASCII conversion */
/* To ASCII conversion */
DATA
(
insert
OID
=
1845
(
to_ascii
PGNSP
PGUID
12
1
0
0
0
f
f
f
t
f
i
1
0
25
"25"
_null_
_null_
_null_
_null_
to_ascii_default
_null_
_null_
_null_
));
DATA
(
insert
OID
=
1845
(
to_ascii
PGNSP
PGUID
12
1
0
0
0
f
f
f
t
f
i
1
0
25
"25"
_null_
_null_
_null_
_null_
to_ascii_default
_null_
_null_
_null_
));
...
...
src/include/utils/builtins.h
View file @
d5448c7d
...
@@ -769,6 +769,8 @@ extern Datum unknownsend(PG_FUNCTION_ARGS);
...
@@ -769,6 +769,8 @@ extern Datum unknownsend(PG_FUNCTION_ARGS);
extern
Datum
pg_column_size
(
PG_FUNCTION_ARGS
);
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
string_agg_transfn
(
PG_FUNCTION_ARGS
);
extern
Datum
string_agg_transfn
(
PG_FUNCTION_ARGS
);
extern
Datum
string_agg_finalfn
(
PG_FUNCTION_ARGS
);
extern
Datum
string_agg_finalfn
(
PG_FUNCTION_ARGS
);
...
...
src/test/regress/expected/aggregates.out
View file @
d5448c7d
...
@@ -1061,3 +1061,26 @@ select string_agg(distinct f1::text, ',' order by f1::text) from varchar_tbl; -
...
@@ -1061,3 +1061,26 @@ select string_agg(distinct f1::text, ',' order by f1::text) from varchar_tbl; -
a,ab,abcd
a,ab,abcd
(1 row)
(1 row)
-- bytea_agg tests
create table bytea_test_table(v bytea);
select bytea_agg(v) from bytea_test_table;
bytea_agg
-----------
(1 row)
insert into bytea_test_table values(decode('ff','hex'));
select bytea_agg(v) from bytea_test_table;
bytea_agg
-----------
\xff
(1 row)
insert into bytea_test_table values(decode('aa','hex'));
select bytea_agg(v) from bytea_test_table;
bytea_agg
-----------
\xffaa
(1 row)
drop table bytea_test_table;
src/test/regress/sql/aggregates.sql
View file @
d5448c7d
...
@@ -416,3 +416,18 @@ select string_agg(distinct f1, ',' order by f1) from varchar_tbl; -- ok
...
@@ -416,3 +416,18 @@ select string_agg(distinct f1, ',' order by f1) from varchar_tbl; -- ok
select
string_agg
(
distinct
f1
::
text
,
','
order
by
f1
)
from
varchar_tbl
;
-- not ok
select
string_agg
(
distinct
f1
::
text
,
','
order
by
f1
)
from
varchar_tbl
;
-- not ok
select
string_agg
(
distinct
f1
,
','
order
by
f1
::
text
)
from
varchar_tbl
;
-- not ok
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
select
string_agg
(
distinct
f1
::
text
,
','
order
by
f1
::
text
)
from
varchar_tbl
;
-- ok
-- bytea_agg tests
create
table
bytea_test_table
(
v
bytea
);
select
bytea_agg
(
v
)
from
bytea_test_table
;
insert
into
bytea_test_table
values
(
decode
(
'ff'
,
'hex'
));
select
bytea_agg
(
v
)
from
bytea_test_table
;
insert
into
bytea_test_table
values
(
decode
(
'aa'
,
'hex'
));
select
bytea_agg
(
v
)
from
bytea_test_table
;
drop
table
bytea_test_table
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment