Re: Connect to a database in a .sql file

Поиск
Список
Период
Сортировка
От Assad Jarrahian
Тема Re: Connect to a database in a .sql file
Дата
Msg-id 4bd3e1480511072331y55a82703ub6862adfc16ea699@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Connect to a database in a .sql file  (Klint Gore <kg@kgb.une.edu.au>)
Ответы Re: Connect to a database in a .sql file  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: Connect to a database in a .sql file  (Richard Huxton <dev@archonet.com>)
Re: Connect to a database in a .sql file  (Sigurdur Gunnlaugsson <sig@fjolnet.net>)
Список pgsql-general
Hi,
    Lets say the script is called myDBSetup.sql

And the script contains:

//CREATE DATABASE section
//CREATE USERS SECTION
//COnnect to db
//CREATE TABLES, FUNCTIONS etc.

this script will be called from psql. The user will log connect to template1 and then run my script. What I really need is after the CREATE DB, I need to switch from template1 to the database name (so the CREATE tables etc will correspond to the right db). This has to be automated and done within the script.

\c does not work in .sql script run in psql.

Any suggestions would be helpful. Thanks.
-assad


On 11/6/05, Klint Gore <kg@kgb.une.edu.au > wrote:
On Sun, 6 Nov 2005 18:06:11 -0700, Assad Jarrahian <jarraa@gmail.com> wrote:
> Hi,
> I am writing a .sql file to create a database, connect to it and create
> tables etc. (basic db setup).
> But I cannot figure out how to connect to the server (what statement) in a
> .sql file.
>
> any help would be appreciated.

What's going to play the script?  If psql, then check out the \c
command.

klint.

+---------------------------------------+-----------------+
: Klint Gore                            : "Non rhyming    :
: EMail   : kg@kgb.une.edu.au           :  slang - the    :
: Snail   : A.B.R.I.                    :  possibilities  :
: Mail      University of New England   :  are useless"   :
:           Armidale NSW 2351 Australia :     L.J.J.      :
: Fax     : +61 2 6772 5376             :                 :
+---------------------------------------+-----------------+

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

Предыдущее
От: "Bob Powell"
Дата:
Сообщение: odbc in postgresql and php
Следующее
От: Richard Huxton
Дата:
Сообщение: Re: Programmatic method to determine currently installed