Outdated Version

You are viewing an older version of this section. View current production version.

DROP AGGREGATE

Removes a single user-defined aggregate function (UDAF) from the specified database.

Syntax

DROP AGGREGATE [IF EXISTS] { function_name | database_name.function_name }

Remarks

Only one function can be removed using the DROP AGGREGATE command.

If DROP AGGREGATE is executed for a function that does not exist, the following error will occur:

memsql> DROP AGGREGATE myaggregate;
ERROR 2219 (HY000): Function 'db1.myaggregate' doesn't exist

However, if the IF EXISTS clause is used and the function does not exist, no error will occur:

memsql> DROP AGGREGATE IF EXISTS myaggregate;
Query OK, 0 rows affected (0.00 sec)

Examples

Dropping a Function in the Current Database

The following example removes an existing function from the current database.

memsql> SHOW AGGREGATES;
+-------------------+
| Aggregates_in_db1 |
+-------------------+
| multiply_hundred  |
| myaggregate       |
+-------------------+
2 rows in set (0.00 sec)

memsql> DROP AGGREGATE myaggregate;
Query OK, 0 rows affected (0.05 sec)

memsql> SHOW AGGREGATES;
+-------------------+
| Aggregates_in_db1 |
+-------------------+
| multiply_hundred  |
+-------------------+
1 row in set (0.00 sec)

Dropping a Function in Another Database

The following example removes an existing function while connected to another database in your MemSQL cluster.

memsql> USE db1;

Database changed

memsql> SHOW AGGREGATES;
+-------------------+
| Aggregates_in_db1 |
+-------------------+
| multiply_hundred  |
| myaggregate       |
+-------------------+
2 rows in set (0.00 sec)

memsql> USE db2;

Database changed

memsql> DROP AGGREGATE db1.myaggregate;
Query OK, 0 rows affected (0.05 sec)

memsql> USE db1;

Database changed

memsql> SHOW AGGREGATES;
+-------------------+
| Aggregates_in_db1 |
+-------------------+
| multiply_hundred  |
+-------------------+
1 row in set (0.00 sec)