Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't drop a table in postgres

Tags:

postgresql

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?

like image 550
Ted Tomlinson Avatar asked Jan 29 '14 18:01

Ted Tomlinson


1 Answers

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.

like image 106
gsiems Avatar answered Oct 21 '22 10:10

gsiems