Create schema with in a specific database from a script file

Поиск
Список
Период
Сортировка
От David G. Johnston
Тема Create schema with in a specific database from a script file
Дата
Msg-id CAKFQuwYvTudTkEuhqxDZJX9Qugb6SDqxn5F+pa7A3iTr-cj3qA@mail.gmail.com
обсуждение исходный текст
Ответ на Create schema with in a specific database from a script file  (Abhra Kar <abhra.kar@gmail.com>)
Список pgsql-general
On Thursday, February 1, 2018, Abhra Kar <abhra.kar@gmail.com> wrote:

     In xyz.sh I executed the following script ---

su -c "psql -c \"\c ABC  \"" postgres

su -c "psql -c \"create schema authorization myschema\"" postgres

 

In the terminal got message “connected to ABC database”. But schema created with in postgres database not with in ABC database.


Right.  psql connected to the Postgres database, executed \c ABC which caused the session to connect to ABC.  Then, seeing no other commands, that psql session disconnected.  Then a brand new session was opened to the postgres database and in that new session created the schema.

Every psql command in a script is independent of all others, there is no state maintained.

For psql scripts in bash I find:

psql <<SQL
<script here>
SQL

To be the better form than trying to use -c.  Or put the psql code in its own file and use -f (really preferred though more files and navigation to deal with).

And you should probably try to avoid using "su" as a crutch to make things work.  Invoking commands as root is dangerous.

David J.

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

Предыдущее
От: Melvin Davidson
Дата:
Сообщение: Re: Create schema with in a specific database from a script file
Следующее
От: Sargez
Дата:
Сообщение: Re: Master-Slave error: the database system is starting up