CREATE DATABASE IF NOT EXISTS in PostgreSQL

From: Japin Li <japinli(at)hotmail(dot)com>
To: "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: CREATE DATABASE IF NOT EXISTS in PostgreSQL
Date: 2022-02-27 14:13:13
Message-ID: MEYP282MB1669A5EEBC791F927D89063EB6009@MEYP282MB1669.AUSP282.PROD.OUTLOOK.COM
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


Hi, hackers

When I try to use CREATE DATABASE IF NOT EXISTS in PostgreSQL, it complains
this syntax is not supported. We can use the following command to achieve
this, however, it's not straightforward.

SELECT 'CREATE DATABASE mydb'
WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'mydb')\gexec

Why don't support CREATE DATABASE IF NOT EXISTS syntax in PostgreSQL?

I create a patch for this, any suggestions?

--
Regrads,
Japin Li.
ChengDu WenWu Information Technology Co.,Ltd.

Attachment Content-Type Size
v1-0001-Add-CREATE-DATABASE-IF-NOT-EXISTS-syntax.patch text/x-patch 4.1 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jille Timmermans 2022-02-27 14:27:38 Re: Support for grabbing multiple consecutive values with nextval()
Previous Message Gunnar "Nick" Bluth 2022-02-27 13:30:33 Re: PATCH: add "--config-file=" option to pg_rewind