DROP TABLE

Warning

At the moment, YDB's compatibility with PostgreSQL is under development, so not all PostgreSQL constructs and functions are supported yet. PostgreSQL compatibility is available for testing in the form of a Docker container, which can be deployed by following these instructions.

Syntax of the DROP TABLE statement:

DROP TABLE [IF EXISTS] <table name>;

The DROP TABLE <table name>; statement is used to delete a table. For example: DROP TABLE people;. If the table being deleted does not exist – an error message will be displayed:

Error: Cannot find table '...' because it does not exist or you do not have access permissions.
Please check correctness of table path and user permissions., code: 2003.

In a number of scenarios, such behavior is not required. For example, if we want to ensure the creation of a new table by deleting the previous one within a single SQL script or a sequence of SQL commands. In such cases, the instruction DROP TABLE IF EXISTS <table name> is used. If the table does not exist, the instruction will return a DROP TABLE message, not an error.

Note

Unlike PostgreSQL, YDB uses optimistic locking. This means that transactions check the conditions for the necessary locks at the end of their operation, not at the beginning. If the lock has been violated during the transaction's execution, such a transaction will end with a Transaction locks invalidated error. In this case, you can try to execute a similar transaction again.