Re: How to do a "CREATE DATABASE" and then connect to it?

Поиск
Список
Период
Сортировка
От Terry Lee Tucker
Тема Re: How to do a "CREATE DATABASE" and then connect to it?
Дата
Msg-id 200606030436.59191.terry@esc1.com
обсуждение исходный текст
Ответ на Re: How to do a "CREATE DATABASE" and then connect to it?  (Joseph Brenner <doom@kzsu.stanford.edu>)
Ответы Re: How to do a "CREATE DATABASE" and then connect to it?  (Frank Finner <postgresql@finner.de>)
Re: How to do a "CREATE DATABASE" and then connect to it?  (Joseph Brenner <doom@kzsu.stanford.edu>)
Список pgsql-general
On Saturday 03 June 2006 04:07 am, Joseph Brenner <doom@kzsu.stanford.edu>
thus communicated:
-->
--> Joshua D. Drake <jd@commandprompt.com> wrote:
-->
--> > Joseph Brenner wrote:
-->
--> > > After you do a "CREATE DATABASE", how do you programatically
--> > > connect to what you just created?
--> > >
--> > > In the psql monitor, you'd use the "\c" command.
--> > >
--> > > If the DATABASE already exists when you connect to postgresql,
--> > > you use the name when you connect (e.g. "dbname=...").
--> > >
--> > > I'm getting the impression I need to do this in multiple steps,
--> > > which is workable, but seems a little silly.
-->
--> > Have you tried reading the documentation?
-->
--> Yup.  Are you sure you've understood my question?
-->
--> It's not a terribly major point, I'm just wondering if it's true that
--> there's no postgres SQL analog of the psql "\c" command.
-->
--> For example, this certainly works in perl:
-->
-->     use DBI;
-->
-->     my $dbh_1 = DBI->connect("dbi:Pg:dbname=template1", $owner,
 $db_password, -->                           { RaiseError => 1, AutoCommit =>
 1 }); -->
-->     $dbh_1->do("CREATE DATABASE new_test_db");
-->
-->     $dbh_1->disconnect();
-->
-->     my $dbh_2 = DBI->connect("dbi:Pg:dbname=new_test_db", $owner,
 $db_password, -->                           { RaiseError => 1, AutoCommit =>
 1 }); -->
-->
-->     $dbh_2->do("CREATE TABLE whocares (meaningless INTEGER, blather
 TEXT)"); -->
-->
--> But the need for those two "DBI->connect"s seems inelegant to me.
-->
--> Do you have any particular portion of the documentation in mind?
-->

I don't see the point. There are two connects either way.
psql:
Connection 1: psql template1
Connection 2: \c new_test_db

Perl:
Connection 1:  my $dbh_1 = DBI->connect("dbi:Pg:dbname=template1", blah, blah
Connection 2:  DBI->connect("dbi:Pg:dbname=new_test_db", $owner, blah, blah

The only difference, at least from my point of view, is the method used and
the extra disconnect(). But even so, the extra disconnect() is not really
necessary.

В списке pgsql-general по дате отправления:

Предыдущее
От: Joseph Brenner
Дата:
Сообщение: Re: How to do a "CREATE DATABASE" and then connect to it?
Следующее
От: Frank Finner
Дата:
Сообщение: Re: How to do a "CREATE DATABASE" and then connect to it?