Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
postgres-lambda-diff
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jakob Huber
postgres-lambda-diff
Commits
3d7ac0d0
Commit
3d7ac0d0
authored
16 years ago
by
Tom Lane
Browse files
Options
Downloads
Patches
Plain Diff
Note that the example aggregate array_accum is comparable to the now
built-in array_agg. Per suggestion from Robert Haas.
parent
170b66a0
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
doc/src/sgml/xaggr.sgml
+13
-10
13 additions, 10 deletions
doc/src/sgml/xaggr.sgml
with
13 additions
and
10 deletions
doc/src/sgml/xaggr.sgml
+
13
−
10
View file @
3d7ac0d0
<!-- $PostgreSQL: pgsql/doc/src/sgml/xaggr.sgml,v 1.3
5
200
7/02/01 00:28:18 momjian
Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/xaggr.sgml,v 1.3
6
200
8/11/20 21:10:44 tgl
Exp $ -->
<sect1 id="xaggr">
<sect1 id="xaggr">
<title>User-Defined Aggregates</title>
<title>User-Defined Aggregates</title>
...
@@ -9,7 +9,7 @@
...
@@ -9,7 +9,7 @@
</indexterm>
</indexterm>
<para>
<para>
Aggregate functions in <productname>PostgreSQL</productname>
Aggregate functions in <productname>PostgreSQL</productname>
are expressed in terms of <firstterm>state values</firstterm>
are expressed in terms of <firstterm>state values</firstterm>
and <firstterm>state transition functions</firstterm>.
and <firstterm>state transition functions</firstterm>.
That is, an aggregate operates using a state value that is updated
That is, an aggregate operates using a state value that is updated
...
@@ -41,7 +41,7 @@
...
@@ -41,7 +41,7 @@
aggregate to work on a data type for complex numbers,
aggregate to work on a data type for complex numbers,
we only need the addition function for that data type.
we only need the addition function for that data type.
The aggregate definition would be:
The aggregate definition would be:
<screen>
<screen>
CREATE AGGREGATE sum (complex)
CREATE AGGREGATE sum (complex)
(
(
...
@@ -80,7 +80,7 @@ SELECT sum(a) FROM test_complex;
...
@@ -80,7 +80,7 @@ SELECT sum(a) FROM test_complex;
the transition function is marked <quote>strict</> (i.e., not to be called
the transition function is marked <quote>strict</> (i.e., not to be called
for null inputs).
for null inputs).
</para>
</para>
<para>
<para>
Another bit of default behavior for a <quote>strict</> transition function
Another bit of default behavior for a <quote>strict</> transition function
is that the previous state value is retained unchanged whenever a
is that the previous state value is retained unchanged whenever a
...
@@ -89,7 +89,7 @@ SELECT sum(a) FROM test_complex;
...
@@ -89,7 +89,7 @@ SELECT sum(a) FROM test_complex;
transition function as strict; instead code it to test for null inputs and
transition function as strict; instead code it to test for null inputs and
do whatever is needed.
do whatever is needed.
</para>
</para>
<para>
<para>
<function>avg</> (average) is a more complex example of an aggregate.
<function>avg</> (average) is a more complex example of an aggregate.
It requires
It requires
...
@@ -132,7 +132,10 @@ CREATE AGGREGATE array_accum (anyelement)
...
@@ -132,7 +132,10 @@ CREATE AGGREGATE array_accum (anyelement)
</programlisting>
</programlisting>
Here, the actual state type for any aggregate call is the array type
Here, the actual state type for any aggregate call is the array type
having the actual input type as elements.
having the actual input type as elements. The behavior of the aggregate
is to concatenate all the inputs into an array of that type.
(Note: the built-in aggregate <function>array_agg</> provides similar
functionality, with better performance than this definition would have.)
</para>
</para>
<para>
<para>
...
@@ -149,14 +152,14 @@ SELECT attrelid::regclass, array_accum(attname)
...
@@ -149,14 +152,14 @@ SELECT attrelid::regclass, array_accum(attname)
pg_tablespace | {spcname,spcowner,spclocation,spcacl}
pg_tablespace | {spcname,spcowner,spclocation,spcacl}
(1 row)
(1 row)
SELECT attrelid::regclass, array_accum(atttypid)
SELECT attrelid::regclass, array_accum(atttypid
::regtype
)
FROM pg_attribute
FROM pg_attribute
WHERE attnum > 0 AND attrelid = 'pg_tablespace'::regclass
WHERE attnum > 0 AND attrelid = 'pg_tablespace'::regclass
GROUP BY attrelid;
GROUP BY attrelid;
attrelid | array_accum
attrelid |
array_accum
---------------+-----------------
---------------+-----------------
----------
pg_tablespace | {
19,26,25,1034
}
pg_tablespace | {
name,oid,text,aclitem[]
}
(1 row)
(1 row)
</programlisting>
</programlisting>
</para>
</para>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment