Database Reference
In-Depth Information
•
prefunc( internal-state, internal-state ) ---> next-
internal-state
•
ffunc( internal-state ) ---> aggregate-value
In the preceding example we only have the
sfunc
.
To test this aggregate, you can try the following code:
CREATE TABLE x(a INT);
INSERT INTO x VALUES (1),(2),(3);
SELECT scube(a) FROM x;
Correct answer for reference:
SELECT sum(a*a*a) FROM x;
Aggregate function description:
array_agg(any element) Concatenates any element
into an array. Example: SELECT
array_agg(anyelement ORDER BY anyelement) FROM
table;
string_agg(text) Concatenates text into a
string. Example: SELECT string_agg(text ORDER
BY text) FROM table;
string_agg(text, delimiter) Concatenates text
into a string delimited by delimiter.
For example,
SELECT string_agg(text, ',' ORDER BY text) FROM
table;
The columns in an
ORDER BY
clause are not necessarily the same as the aggreg-
atedcolumn,asshowninthefollowingcodethatreferencesatablenamed
product
with columns
store_id
,
product_name
, and
quantity
:
SELECT store_id, array_agg(product_name ORDER
BY quantity desc) FROM product GROUP BY
store_id;
Search WWH ::
Custom Search