Reputation: 783
I'm new to postgresql and I can't seem to get it to drop a table.
db_dev=# \dt
List of relations
Schema | Name | Type | Owner
--------+-------------+-------+-------
public | DataSources | table | ted
public | Emails | table | ted
public | Users | table | ted
(3 rows)
When I try to delete the users table it gives an error:
db_dev=# drop table Users;
ERROR: table "users" does not exist
What am I doing wrong?
Upvotes: 16
Views: 15594
Reputation: 3790
The problem is that your Users table is mixed case (and object names in Postgres are case sensitive). Without quotes around the table name Postgres will case fold the supplied name to "users"-- which doesn't exist. Your solution of quoting the table name works, not because users is a reserved name but because, by quoting it, you are telling Postgres to drop the "Users" table rather than the "users" table.
Upvotes: 33
Reputation: 1427
It seems that you are doing it right, but you can try doing this:
DROP TABLE IF EXISTS Users;
or this:
DROP TABLE IF EXISTS Public.Users;
If exists will be deleted, and if not exists you will know.
Upvotes: 6