Reputation: 376
In my Ruby-on-Rails database.yml
file, I accidentally created a PostgreSQL database with a forward slash (/
) in its name.
I have been unable to remove this database via psql commands, trying with various escape sequences.
Upvotes: 2
Views: 2242
Reputation: 1122092
Surround your database name in quotes:
DROP DATABASE "database/withslash";
From the Identifiers and Keywords documentation:
There is a second kind of identifier: the delimited identifier or quoted identifier. It is formed by enclosing an arbitrary sequence of characters in double-quotes ("). A delimited identifier is always an identifier, never a key word. So "select" could be used to refer to a column or table named "select", whereas an unquoted select would be taken as a key word and would therefore provoke a parse error when used where a table or column name is expected. The example can be written with quoted identifiers like this:
UPDATE "my_table" SET "a" = 5;
Quoted identifiers can contain any character, except the character with code zero.
Do note that quoted identifiers are case sensitive.
You cannot drop a database while connected to that database though, so maybe you want to use the command line dropdb
command. Your shell will parse the quotes, so you want to escape the quotes:
dropdb \"database/withslash\"
Upvotes: 7