Skip site navigation (1) Skip section navigation (2)

Re: Creating DB programmatically?

From: Pushpendra Singh Thakur <thakur(at)corexprts(dot)com>
To: Jayadevan(dot)Maymala(at)ibsplc(dot)com
Cc: pgsql-novice(at)postgresql(dot)org, pgsql-novice-owner(at)postgresql(dot)org
Subject: Re: Creating DB programmatically?
Date: 2011-07-12 14:31:36
Message-ID: CAH55RCEaB2VAD5V-HKVX0AJ-cZjH-kU_aUNju6Xfa=LR0U4PcA@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-novice
some typing error plz read connect to database using maintenance database
"postgres"

On 12 July 2011 20:00, Pushpendra Singh Thakur <thakur(at)corexprts(dot)com> wrote:

> Step 1 connect to user using maintenance db "ie postgres"
> Step 2 check whether database exists or not "SELECT 1 AS result FROM
> pg_database
> WHERE datname='abc'"
> Step 3 if not run "create database ...."
>
> simple..
>
>
> On 12 July 2011 17:14, Frank Bax <fbax(at)sympatico(dot)ca> wrote:
>
>> 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.
>>
>>
>>
>> --
>> Sent via pgsql-novice mailing list (pgsql-novice(at)postgresql(dot)org)
>> To make changes to your subscription:
>> http://www.postgresql.org/**mailpref/pgsql-novice<http://www.postgresql.org/mailpref/pgsql-novice>
>>
>
>
>
> --
> Pushpendra Singh Thakur
>
> *COREEXPERTS Technologies Private Limited*
> Business Process Automation & IT Support Services
> http://www.corexprts.com
> Phone - 91-761-4070036
> Fax - 91-761-4010530
> SMS - 97-555-21174
>



-- 
Pushpendra Singh Thakur

*COREEXPERTS Technologies Private Limited*
Business Process Automation & IT Support Services
http://www.corexprts.com
Phone - 91-761-4070036
Fax - 91-761-4010530
SMS - 97-555-21174

In response to

pgsql-novice by date

Next:From: Greg Sabino MullaneDate: 2011-07-12 15:14:37
Subject: Re: pgpass.cong file becomes empty
Previous:From: Pushpendra Singh ThakurDate: 2011-07-12 14:30:19
Subject: Re: Creating DB programmatically?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group