openlang

How should a hyphenated PostgreSQL database name be quoted?

I want to give a database a new name containing a hyphen (-).

ALTER DATABASE primarydb
RENAME TO primarydb-secondary;

But psql reports this error:

ERROR:  syntax error at or near "-"

Which escape sequence handles the "-" character, or how should I accomplish this?

Note: I also tried '-' without any success.

Thank you.

The conversation continues 3

Follow the reasoning
  1. Permalink

    Putting it inside double quotes should work. However, every reference to that database will need to keep using the quoted identifier.

    ALTER DATABASE primarydb
    RENAME TO "primarydb-secondary";

Other sides of the same question

  1. Missing field through a derived table in SQL

    I'm executing the following SQL statement: It produces the following error: #1054 - Unknown column 'shipping.post_id' in 'on…

    Replies 2Latest activity sql
  2. Testing D arrays for a matching entry

    with associative arrays this is possible how is this done with ordinary arrays? I'd like a validation expression, for example

    Replies 2Latest activity d
  3. Removing an optional column safely with PostgreSQL 9+

    I want to remove a column belonging to a table. What's the way to determine whether that column is present? I read the manual…

    Replies 2Latest activity sql