Novice
Novice

Reputation: 393

PostgreSQL sytax - DROP DTB

I created database with name -encoding=UTF-8 (miss clicked)

nothing worked to remove databese.

\l
     name           |  owner  | Encoding | Collate     | Ctype  
---------------------------------------------------------------------
    -encoding=UTF-8 | test1   | UTF8     | en_US.UTF-8 | en_US.UTF-8

DROP DATABASE -encoding=UTF-8;
ERROR: syntax error at near "-"
LINE 1: DROP DATABASE -encoding=UTF-8;

Do i have any chance to drop database or i have to reinstall PostgreSQL ?

Upvotes: 1

Views: 215

Answers (2)

user330315
user330315

Reputation:

Identifiers with special characters need to be enclosed in double quotes:

DROP DATABASE "-encoding=UTF-8";

For details on how to use identifiers, please see the manual:
http://www.postgresql.org/docs/current/static/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS

The name might contain leading or trailing whitepace. To get a properly quoted identifier, you can use this query:

select quote_ident(datname)
from pg_database;

Upvotes: 2

Mureinik
Mureinik

Reputation: 311163

- isn't usually a legal character in object names. If you want to use it, you should protect the name with quotes ("):

DROP DATABASE "-encoding=UTF-8";

Upvotes: 0

Related Questions