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:53:18
Message-ID: CAP6d-HWaxvTWTYf+BRF0EA=_3POieWhwYwAkgRQZcXoKFoWL-w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

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.

> 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.

> that I'm writing in C++ and using the 'libpq' interface?]
>
>> From: esiotrot(at)gmail(dot)com
>> Date: Tue, 12 Jul 2011 09:12:04 +0200
>> Subject: Re: [NOVICE] Creating DB programmatically?
>> To: rmw256(at)hotmail(dot)com
>> CC: pgsql-novice(at)postgresql(dot)org
>>
>> On 12 July 2011 08:48, Roy's Email <rmw256(at)hotmail(dot)com> wrote:
>> > OK, based on what I'm hearing, I'm clearly missing something.  I'm
>> > looking
>> > to create the DB from within my application; not from some shell/command
>> > line window.  Also, I want my application to run on "any" Windows
>> > machine,
>> > so I can't dictate ancillary programs other than requiring that
>> > postgreSQL
>> > be present.
>> Try connecting to e.g. the "template1" database in order to check for
>> existence of your database and issue "CREATE DATABASE ..." from there.
>>
>> > ________________________________
>> > To: rmw256(at)hotmail(dot)com
>> > CC: pgsql-novice(at)postgresql(dot)org; pgsql-novice-owner(at)postgresql(dot)org
>> > Subject: Re: [NOVICE] Creating DB programmatically?
>> > From: Jayadevan(dot)Maymala(at)ibsplc(dot)com
>> > Date: Tue, 12 Jul 2011 10:49:17 +0530
>> >
>> > Hello,
>> >
>> >>
>> >> On Mon, Jul 11, 2011 at 11:00 PM, Roy's Email <rmw256(at)hotmail(dot)com>
>> >> wrote:
>> >> > This is on Windows, I'm afraid.
>> >>
>> >> well, I have good news --  both psql and grep work just fine on
>> >> windows :-).  unfortunately batch is a pretty horrible scriptring
>> >> language, but if you need to get real work done you can find a
>> >> standalone .exe (like bash.exe, grep.exe, find.exe etc).
>> >>
>> > May be
>> > http://gnuwin32.sourceforge.net/packages/coreutils.htm
>> > But anyway, when we use psql, we are connecting to postgresql.
>> > Regards,
>> > Jayadevan

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

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Michael Wood 2011-07-12 08:56:12 Re: Creating DB programmatically?
Previous Message Thomas Kellerer 2011-07-12 08:19:49 Re: Creating DB programmatically?