Re: Creating DB programmatically? - Mailing list pgsql-novice

From Thomas Kellerer
Subject Re: Creating DB programmatically?
Date
Msg-id ivh02f$fot$1@dough.gmane.org
Whole thread Raw
In response to Creating DB programmatically?  (Roy's Email <rmw256@hotmail.com>)
List pgsql-novice
Roy's Email, 12.07.2011 01:40:
> I would like to create my DB programmatically. I.e. If the DB does
> not already exist, I would like to be able to create (and populate)
> it from within my application. Is there some way to do this?
> Everything I see seems to require connecting to an existing DB before
> you can do anything.
>

Connect to one of the template databases (template0, template1) from within your program (those databases are always
there).
Then you have a valid connection through which you can execute the CREATE DATABASE statement.

You can also run a "SELECT datname FROM pg_database" using that connection to test if your database is already there.

Thomas



pgsql-novice by date:

Previous
From: Roy's Email
Date:
Subject: Re: Creating DB programmatically?
Next
From: Michael Wood
Date:
Subject: Re: Creating DB programmatically?