Created
March 27, 2024 13:50
-
-
Save CHERTS/af1ce5338f837af5667e6a4ff60a4596 to your computer and use it in GitHub Desktop.
CREATE DATABASE NOT EXISTS in PostgreSQL (workaround from within psql)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# native using psql | |
SELECT 'CREATE DATABASE mydb' WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'mydb')\gexec | |
# native using shell + psql | |
echo "SELECT 'CREATE DATABASE mydb' WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'mydb')\gexec" | psql |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment