Languages
[Edit]
EN

PostgreSQL - Create database

0 points
Created by:
marc_so
1014

In this article, we would like to show you how to create database in PostgreSQL.

Quick solution:

CREATE DATABASE "database_name";

CREATE DATABASE example

In this example, we will create a new database - diraskDB.

Query:

CREATE DATABASE "diraskDB";

CREATE DATABASE IF NOT EXISTS example

You can optionally add IF NOT EXISTS statement, so if the database already exists you won't get an error.

Query:

CREATE DATABASE IF NOT EXISTS "diraskDB";

Popular error

If you try to create a database that already exists with CREATE DATABASE query you will get an error:

PostgreSQL - SQL Error: Can't create database..
PostgreSQL - SQL Error: Can't create database.

If you try to CREATE DATABASE IF NOT EXIST you will get a warning instead:

PostgreSQL - Note: Can't create database..
PostgreSQL - Note: Can't create database.
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

PostgreSQL

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join