4

I am trying to create the Postgres database using the terminal,

Normally we can create the database like

CREATE DATABASE mydatabase;

but I wanted to create with the database with a dot. like

CREATE DATABASE my.database;

I was trying to escape the characters. but it doesn't work

CREATE DATABASE my.\database;

CREATE DATABASE my\.database;

as an expected output, it should create the database named my.database

2
  • 1
    CREATE DATABASE "my.database";. But since . is used as seperator for schemas, tables, columns etc. this will probably lead to problems down the road.
    – madflow
    Commented Oct 23, 2019 at 10:23
  • "How to create Postgres database containing dot in it's name?" indeed @madflow sounds like trouble as it looks like the topicstarter is trying to emulate namespaces from Java or something like that ...CREATE DATABASE "com.domain.type", CREATE DATABASE "com.domain.type.sub_type"..... Commented Oct 23, 2019 at 10:31

1 Answer 1

7

you should create the database using

create database "my.database";

3
  • 6
    Should be followed by "but don't because it's a terrible idea".
    – 404
    Commented Oct 23, 2019 at 10:26
  • @404 with the why it is a terrible one.
    – ntdash
    Commented Oct 13, 2023 at 22:47
  • 4
    @ntdash Because the . is used to separate the table name from schema, or column from table. For example, SELECT * FROM schema1.table1 or SELECT a.id, b.val FROM (some join). You'll also never be able to use the table without quoting it. While it may not be illegal to have a dot in a table name, you're setting yourself and anyone else working on the codebase up for constant confusion, bugs, and hopefully hate in your direction for such a stupid decision.
    – 404
    Commented Oct 14, 2023 at 9:37

Not the answer you're looking for? Browse other questions tagged or ask your own question.