title: Simulate CREATE DATABASE IF NOT EXISTS for PostgreSQL?
body: <p>I want to create a database which does not exist through JDBC. Unlike MySQL, PostgreSQL does not support <code>create if not exists</code> syntax. What is the best way to accomplish this?</p>
  
  <p>The application does not know if the database exists or not. It should check and if the database exists it should be used. So it makes sense to connect to the desired database and if connection fails due to non-existence of database it should create new database (by connecting to the default <code>postgres</code> database). I checked the error code returned by Postgres but I could not find any relevant code that species the same.</p>
  
  <p>Another method to achieve this would be to connect to the <code>postgres</code> database and check if the desired database exists and take action accordingly. The second one is a bit tedious to work out.</p>
  
  <p>Is there any way to achieve this functionality in Postgres?</p>