Re: Creating DB programmatically?

From: Frank Bax <fbax(at)sympatico(dot)ca>
To: PostgreSQL List - Novice <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Creating DB programmatically?
Date: 2011-07-12 11:44:26
Message-ID: 4E1C339A.50401@sympatico.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On 07/12/11 03:31, Roy's Email wrote:
> Now I am particularly confused. How do I issue "CREATE DATABASE ..."
> from 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 I'm writing in C++ and using the 'libpq' interface?]

Let's assume for the moment; that you know how to connect to an existing
database and execute an SQL command like "SELECT ....".

Simply modify your code:
* change your connect command so it connects to "template1"
* change your "SELECT ..." statement to "CREATE DATABASE ..."
* close the connection and make a connection to database just created.

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Francisco Leovey 2011-07-12 11:44:43 Re: Creating DB programmatically?
Previous Message Michael Wood 2011-07-12 08:56:12 Re: Creating DB programmatically?