Re: Creating DB programmatically?

From: Michael Wood <esiotrot(at)gmail(dot)com>
To: "Roy's Email" <rmw256(at)hotmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Creating DB programmatically?
Date: 2011-07-12 08:56:12
Message-ID: CAP6d-HVAAmsVtJGfCcfobYhOH8yNQBXKjYAaCi7LjqE7csRK4A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On 12 July 2011 10:53, Michael Wood <esiotrot(at)gmail(dot)com> wrote:
> On 12 July 2011 09:31, Roy's Email <rmw256(at)hotmail(dot)com> wrote:
>> Now I am particularly confused.  How do I issue "CREATE DATABASE ..." from
>
> Well, I've never tried it myself, but you can do it from "psql" and
> that connects to Postgres in order to do it.

Sorry if the above is not as clear as it could be.

To clarify, I do not mean that you should use psql to create the
database. Only that psql does exactly the sort of thing you want to
be able to do, so it is possible :)

You only need to connect to one of the existing databases in order to
check for the existence of other databases or create a new one. And
template0, template1 are predefined databases that should exist unless
something is wrong with the Postgres installation.

>> my program?  I thought that I needed a connection (PGconn) before I could
>> execute a command and I don't believe I have a valid connection if my
>> attempt to connect to a (non-existent) DB fails.  [Does it change anything
>
> That's why I said you should first connect to the "template1"
> database, which will exist.

--
Michael Wood <esiotrot(at)gmail(dot)com>

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Frank Bax 2011-07-12 11:44:26 Re: Creating DB programmatically?
Previous Message Michael Wood 2011-07-12 08:53:18 Re: Creating DB programmatically?