HiveBrain v1.2.0
Get Started
← Back to all entries
gotchasqlMinor

Why does Postgresql tell me the database does not exist?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
postgresqlwhytheexisttelldatabasedoesnot

Problem

I created a Ruby on Rails application just for demonstration to a colleague and then deleted the application, but I did not delete the database which was also created using Postgresql.

I go into posgresql like so:

```
psql postgres

postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
--------------------------------------+--------+----------+-------------+-------------+-------------------
GenerateApp_development | danale | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
GenerateApp_test | danale | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
GeneratorApp_development | danale | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
GeneratorApp_test | danale | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
Overtime_development | danale | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
Overtime_test | danale | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
RoutingApp_development | danale | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
RoutingApp_test | danale | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
dancortesPortfolio_development | danale | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
dancortesPortfolio_test | danale | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
freelance_camp_documents_development | danale | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
freelance_camp_documents_test | danale | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
freelance_camp_proposal_development | danale | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
freelance_camp_proposal_test | danale | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
postgres | danale | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | danale | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/danale +
| |

Solution

You need to double quote the name. In PostgreSQL we never double quote names. If you follow the convention, PostgreSQL will convert the unquoted identifier to lower case. In your case, that which created the db used double quotes.

Now you have a capital letter in the identifier.

From now on you have to double quote the identifier.

Not,

postgres=# DROP DATABASE RoutingApp_development;


But,

postgres=# DROP DATABASE "RoutingApp_development";

Code Snippets

postgres=# DROP DATABASE RoutingApp_development;
postgres=# DROP DATABASE "RoutingApp_development";

Context

StackExchange Database Administrators Q#182033, answer score: 6

Revisions (0)

No revisions yet.