Re: a database can be created but not droped

From: Julien Rouhaud <rjuju123(at)gmail(dot)com>
To: Matthias Apitz <guru(at)unixarea(dot)de>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: a database can be created but not droped
Date: 2022-08-01 09:27:53
Message-ID: 20220801092753.mdynsqehkyfhdvx2@jrouhaud
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

On Mon, Aug 01, 2022 at 11:22:33AM +0200, Matthias Apitz wrote:
>
> This is with 14.1 on Linux. I have created a new database with
>
> $ createdb -U sisis -T template0 SRP-27097
>
> I can connect to it, created tables and fill them with SQL:
>
> but I can not drop the database:
>
> $ psql -Usisis -dtestdb
> psql (14.1)
> Geben Sie »help« für Hilfe ein.
>
> testdb=# DROP DATABASE IF EXISTS SRP-27097 WITH FORCE;
> ERROR: syntax error at or near "-"
> ZEILE 1: DROP DATABASE IF EXISTS SRP-27097 WITH FORCE;
>
> Why is this?

It's because createdb a command that knows how to quote identifiers and will do
automatically for you. At the SQL level you have to properly quote identifier,
so this command will work:

DROP DATABASE IF EXISTS "SRP-27097" WITH FORCE;

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Frank Streitzig 2022-08-01 09:30:41 Re: a database can be created but not droped
Previous Message Matthias Apitz 2022-08-01 09:22:33 a database can be created but not droped