Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs][YSQL] CREATE AGGREGATE, DROP AGGREGATE #2329

Merged
merged 8 commits into from
Sep 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/content/latest/api/ysql/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ DDL statements define the structures in a database, change their definitions, as
|-----------|-------------|
| [`ALTER DATABASE`](commands/ddl_alter_db) | Change database definition |
| [`ALTER TABLE`](commands/ddl_alter_table) | Change table definition |
| [`CREATE AGGREGATE`](commands/ddl_create_aggregate) | Create a new aggregate |
| [`CREATE DATABASE`](commands/ddl_create_database) | Create a new database |
| [`CREATE INDEX`](commands/ddl_create_index) | Create a new index |
| [`CREATE SCHEMA`](commands/ddl_create_schema) | Create a new schema (namespace) |
Expand All @@ -43,6 +44,7 @@ DDL statements define the structures in a database, change their definitions, as
| [`CREATE TABLE AS`](commands/ddl_create_table_as) | Create a new table |
| [`CREATE TYPE`](commands/ddl_create_type) | Create a new type |
| [`CREATE VIEW`](commands/ddl_create_view) | Create a new view |
| [`DROP AGGREGATE`](commands/ddl_drop_aggregate) | Delete an aggregate |
| [`DROP DATABASE`](commands/ddl_drop_database) | Delete a database from the system |
| [`DROP SEQUENCE`](commands/ddl_drop_sequence) | Delete a sequence generator |
| [`DROP TABLE`](commands/ddl_drop_table) | Delete a table from a database |
Expand Down Expand Up @@ -107,7 +109,7 @@ TCL statements manage transactions of operations on the database.
| Statement | Description |
|-----------|-------------|
| [`COPY`](commands/cmd_copy) | Copy data between tables and files |
| [`DO`](commands/cmd_doc) | Execute an anonymous code block |
| [`DO`](commands/cmd_do) | Execute an anonymous code block |

## Language elements

Expand Down
4 changes: 3 additions & 1 deletion docs/content/latest/api/ysql/commands/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ The following SQL statements are supported by the YugaByte Structured Query Lang
| [`COMMENT`](ddl_comment) | Adds a comment on a database object |
| [`COMMIT`](txn_commit) | Commits a transaction |
| [`COPY`](cmd_copy) | Copy data between tables and files |
| [`CREATE AGGREGATE`](ddl_create_aggregate) | Create a new aggregate |
| [`CREATE DATABASE`](ddl_create_database) | Create a new database |
| [`CREATE DOMAIN`](ddl_create_domain) | Create a new domain |
| [`CREATE INDEX`](ddl_create_index) | Create a new index |
Expand All @@ -38,7 +39,8 @@ The following SQL statements are supported by the YugaByte Structured Query Lang
| [`CREATE VIEW`](ddl_create_view) | Create a new view |
| [`DEALLOCATE`](perf_deallocate) | Deallocate a prepared statement |
| [`DELETE`](dml_delete) | Delete rows from a table |
| [`DO`](commands/cmd_doc) | Execute an anonymous code block |
| [`DO`](cmd_do) | Execute an anonymous code block |
| [`DROP AGGREGATE`](ddl_drop_aggregate) | Delete an aggregate |
| [`DROP DATABASE`](ddl_drop_database) | Delete a database from the system |
| [`DROP DOMAIN`](ddl_drop_domain) | Delete a domain |
| [`DROP SEQUENCE`](ddl_drop_sequence) | Delete a sequence generator |
Expand Down
4 changes: 2 additions & 2 deletions docs/content/latest/api/ysql/commands/ddl_comment.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ Use the `COMMENT` statement to set, update, or remove a comment on a database ob

<div class="tab-content">
<div id="grammar" class="tab-pane fade show active" role="tabpanel" aria-labelledby="grammar-tab">
{{% includeMarkdown "../syntax_resources/commands/comment_on,aggregate_signature.grammar.md" /%}}
{{% includeMarkdown "../syntax_resources/commands/comment_on.grammar.md" /%}}
</div>
<div id="diagram" class="tab-pane fade" role="tabpanel" aria-labelledby="diagram-tab">
{{% includeMarkdown "../syntax_resources/commands/comment_on,aggregate_signature.diagram.md" /%}}
{{% includeMarkdown "../syntax_resources/commands/comment_on.diagram.md" /%}}
</div>
</div>

Expand Down
119 changes: 119 additions & 0 deletions docs/content/latest/api/ysql/commands/ddl_create_aggregate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
---
title: CREATE AGGREGATE
linkTitle: CREATE AGGREGATE
summary: Create a new aggregate
description: CREATE AGGREGATE
menu:
latest:
identifier: api-ysql-commands-create-aggregate
parent: api-ysql-commands
aliases:
- /latest/api/ysql/ddl_create_aggregate/
isTocNested: true
showAsideToc: true
---

## Synopsis

Use the `CREATE AGGREGATE` statement to create a new aggregate function. There are three ways to
create aggregates.

## Syntax

<ul class="nav nav-tabs nav-tabs-yb">
<li >
<a href="#grammar" class="nav-link active" id="grammar-tab" data-toggle="tab" role="tab" aria-controls="grammar" aria-selected="true">
<i class="fas fa-file-alt" aria-hidden="true"></i>
Grammar
</a>
</li>
<li>
<a href="#diagram" class="nav-link" id="diagram-tab" data-toggle="tab" role="tab" aria-controls="diagram" aria-selected="false">
<i class="fas fa-project-diagram" aria-hidden="true"></i>
Diagram
</a>
</li>
</ul>

<div class="tab-content">
<div id="grammar" class="tab-pane fade show active" role="tabpanel" aria-labelledby="grammar-tab">
{{% includeMarkdown "../syntax_resources/commands/create_aggregate,create_aggregate_normal,create_aggregate_order_by,create_aggregate_old,aggregate_arg,aggregate_normal_option,aggregate_order_by_option,aggregate_old_option.grammar.md" /%}}
</div>
<div id="diagram" class="tab-pane fade" role="tabpanel" aria-labelledby="diagram-tab">
{{% includeMarkdown "../syntax_resources/commands/create_aggregate,create_aggregate_normal,create_aggregate_order_by,create_aggregate_old,aggregate_arg,aggregate_normal_option,aggregate_order_by_option,aggregate_old_option.diagram.md" /%}}
</div>
</div>

## Semantics

The order of options does not matter. Even the mandatory options `BASETYPE`, `SFUNC`, and `STYPE`
may appear in any order.

See the semantics of each option in the [PostgreSQL docs][postgresql-docs-create-aggregate].

## Examples

Normal syntax example.

```sql
yugabyte=# CREATE AGGREGATE sumdouble (float8) (
STYPE = float8,
SFUNC = float8pl,
MSTYPE = float8,
MSFUNC = float8pl,
MINVFUNC = float8mi
);
yugabyte=# CREATE TABLE normal_table(
f float8,
i int
);
yugabyte=# INSERT INTO normal_table(f, i) VALUES
(0.1, 9),
(0.9, 1);
yugabyte=# SELECT sumdouble(f), sumdouble(i) FROM normal_table;
```

Order by syntax example.

```sql
yugabyte=# CREATE AGGREGATE my_percentile_disc(float8 ORDER BY anyelement) (
STYPE = internal,
SFUNC = ordered_set_transition,
FINALFUNC = percentile_disc_final,
FINALFUNC_EXTRA = true,
FINALFUNC_MODIFY = read_write
);
yugabyte=# SELECT my_percentile_disc(0.1), my_percentile_disc(0.9)
WITHIN GROUP (ORDER BY typlen)
FROM pg_type;
```

Old syntax example.

```sql
yugabyte=# CREATE AGGREGATE oldcnt(
SFUNC = int8inc,
BASETYPE = 'ANY',
STYPE = int8,
INITCOND = '0'
);
yugabyte=# SELECT oldcnt(*) FROM pg_aggregate;
```

Zero-argument aggregate example.

```sql
yugabyte=# CREATE AGGREGATE newcnt(*) (
SFUNC = int8inc,
STYPE = int8,
INITCOND = '0',
PARALLEL = SAFE
);
yugabyte=# SELECT newcnt(*) FROM pg_aggregate;
```

## See also

- [`DROP AGGREGATE`](../ddl_drop_aggregate)

[postgresql-docs-create-aggregate]: https://www.postgresql.org/docs/current/sql-createaggregate.html
99 changes: 99 additions & 0 deletions docs/content/latest/api/ysql/commands/ddl_drop_aggregate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
---
title: DROP AGGREGATE
linkTitle: DROP AGGREGATE
summary: Remove an aggregate
description: DROP AGGREGATE
menu:
latest:
identifier: api-ysql-commands-drop-aggregate
parent: api-ysql-commands
aliases:
- /latest/api/ysql/ddl_drop_aggregate/
isTocNested: true
showAsideToc: true
---

## Synopsis

Use the `DROP AGGREGATE` statement to remove an aggregate.

## Syntax

<ul class="nav nav-tabs nav-tabs-yb">
<li >
<a href="#grammar" class="nav-link active" id="grammar-tab" data-toggle="tab" role="tab" aria-controls="grammar" aria-selected="true">
<i class="fas fa-file-alt" aria-hidden="true"></i>
Grammar
</a>
</li>
<li>
<a href="#diagram" class="nav-link" id="diagram-tab" data-toggle="tab" role="tab" aria-controls="diagram" aria-selected="false">
<i class="fas fa-project-diagram" aria-hidden="true"></i>
Diagram
</a>
</li>
</ul>

<div class="tab-content">
<div id="grammar" class="tab-pane fade show active" role="tabpanel" aria-labelledby="grammar-tab">
{{% includeMarkdown "../syntax_resources/commands/drop_aggregate,aggregate_signature.grammar.md" /%}}
</div>
<div id="diagram" class="tab-pane fade" role="tabpanel" aria-labelledby="diagram-tab">
{{% includeMarkdown "../syntax_resources/commands/drop_aggregate,aggregate_signature.diagram.md" /%}}
</div>
</div>

## Semantics

See the semantics of each option in the [PostgreSQL docs][postgresql-docs-drop-aggregate].

## Examples

Basic example.

```sql
yugabyte=# CREATE AGGREGATE newcnt(*) (
sfunc = int8inc,
stype = int8,
initcond = '0',
parallel = safe
);
yugabyte=# DROP AGGREGATE newcnt(*);
```

`IF EXISTS` example.

```sql
yugabyte=# DROP AGGREGATE IF EXISTS newcnt(*);
yugabyte=# CREATE AGGREGATE newcnt(*) (
sfunc = int8inc,
stype = int8,
initcond = '0',
parallel = safe
);
yugabyte=# DROP AGGREGATE IF EXISTS newcnt(*);
```

`CASCADE` and `RESTRICT` example.

```sql
yugabyte=# CREATE AGGREGATE newcnt(*) (
sfunc = int8inc,
stype = int8,
initcond = '0',
parallel = safe
);
yugabyte=# CREATE VIEW cascade_view AS
SELECT newcnt(*) FROM pg_aggregate;
yugabyte=# -- The following should error:
yugabyte=# DROP AGGREGATE newcnt(*) RESTRICT;
yugabyte=# -- The following should error:
yugabyte=# DROP AGGREGATE newcnt(*);
yugabyte=# DROP AGGREGATE newcnt(*) CASCADE;
```

## See also

- [`CREATE AGGREGATE`](../ddl_create_aggregate)

[postgresql-docs-drop-aggregate]: https://www.postgresql.org/docs/current/sql-dropaggregate.html

This file was deleted.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
```
comment_on ::= COMMENT ON
comment_on ::= COMMENT ON
{ ACCESS METHOD object_name
| AGGREGATE aggregate_name ( aggregate_signature )
| CAST ( source_type AS target_type )
Expand Down Expand Up @@ -45,10 +45,5 @@ comment_on ::= COMMENT ON
| TRANSFORM FOR type_name LANGUAGE lang_name
| TRIGGER trigger_name ON table_name
| TYPE object_name
| VIEW object_name } IS { '<Text Literal>' | NULL }

aggregate_signature ::= * | [ argmode ] [ argname ] argtype [ , ... ]
| [ [ argmode ] [ argname ] argtype [ , ... ] ]
ORDER BY [ argmode ] [ argname ] argtype
[ , ... ]
| VIEW object_name } IS { '<Text Literal>' | NULL }
```
Loading