EN
PostgreSQL - Create database
0
points
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..](/static/bucket/1617984960075-Jw8Qn28QbP--image.png)
If you try to CREATE DATABASE IF NOT EXIST
you will get a warning instead:
![PostgreSQL - Note: Can't create database..](/static/bucket/1617985029344-67oY6O0DE1--image.png)