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. 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

8

you should create the database using

create database "my.database";

Sign up to request clarification or add additional context in comments.

3 Comments

Should be followed by "but don't because it's a terrible idea".
@404 with the why it is a terrible one.
@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.

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.