2

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.

2
  • @DanielNova: \ is a back slash, a forward slash is this: /. You might want to re-think your edit. Commented Sep 15, 2012 at 21:43
  • @a_horse_with_no_name Haha, yeah that was a bit of a fail, I blame lack of sleep. Commented Sep 15, 2012 at 21:46

1 Answer 1

7

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\"
Sign up to request clarification or add additional context in comments.

2 Comments

Hi. Maybe in my original question I wrote backslash...however, what I meant was forward slash, and in this case I'm trying to delete a database whose name contains a forward slash (not a table). Regards, Allan.
@lagouyn: ah, it was late for me as well. :-) Updated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.