Re: Create schema with in a specific database from a script file

From: Melvin Davidson <melvin6925(at)gmail(dot)com>
To: Abhra Kar <abhra(dot)kar(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Create schema with in a specific database from a script file
Date: 2018-02-02 02:53:16
Message-ID: CANu8FizHRPie9vm8TNRfsjx185dBg0zg3k6zufs1Bpu_5u2ZFw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Feb 1, 2018 at 9:42 PM, Abhra Kar <abhra(dot)kar(at)gmail(dot)com> wrote:

> *sudo **-u** postgres createdb ABC*
>
> *su **-c* *"**psql -d ABC**"*
>
> *if [* *$3* *==* *'xxxxx'* *]*
>
> *then*
>
> *su **-c* *"**psql -c **\"**grant all privileges on database ABC** to
> xxxx**\"**"** postgres*
>
> *su **-c* *"**psql -c **\"**create schema authorization xxxx**\"**"**
> postgres*
>
> *else*
>
> *su **-c* *"**psql -c **\"**grant all privileges on database ABC to yyyy*
> *\"**"** postgres*
>
> *su **-c* *"**psql -c **\"**create schema authorization xxxx**\"**"*
> * postgres*
>
> *fi*
>
>
> Hi Melvin,
> I executed the above script but xxxx schema created with
> in postgres db not with in ABC db. And in terminal didn't show the message
> connected to ABC database. What is wrong I am doing here?
>
> Regards,
> Abhra
>
> On Fri, Feb 2, 2018 at 7:48 AM, Melvin Davidson <melvin6925(at)gmail(dot)com>
> wrote:
>
>>
>>
>> On Thu, Feb 1, 2018 at 9:09 PM, Abhra Kar <abhra(dot)kar(at)gmail(dot)com> wrote:
>>
>>> Hi,
>>>
>>> I have to write script for psql in a xyz.sh file which should create
>>> a schema in a specific data.In psql prompt I achieve it like --
>>>
>>>
>>> postgres=# \c ABC
>>>
>>> ABC=# create schema authorization myschema
>>>
>>>
>>>
>>> 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.
>>>
>>> What should be the proper script ?
>>>
>>>
>>>
>>> Thanks and Regards,
>>>
>>> Abhra
>>>
>>>
>>
>> *> But schema created with in postgres database not with in ABC database.
>> *
>>
>> *Just specify the database in the command line:*
>>
>> *EG: su -c "psql -d ABC"*
>>
>>
>> --
>> *Melvin Davidson*
>> I reserve the right to fantasize. Whether or not you
>> wish to share my fantasy is entirely up to you.
>>
>
>

*> I executed the above script but xxxx schema created with in postgres db
not with in ABC db ...*

*1. Please do not top post. The convention is to bottom post in this list.*

*2. You code is not a proper bash script. I suggest you google how to write
bash scripts as this list is*

* is for PostgreSQL help, not bash*

*3. You are just submitting MULTIPLE psql commands. You need to just start
the psql session, then *

* submit all additional commands inside the psql session.*

*EG: psql -d somedb* *grant all privileges on database ABC** to xxxx*
*;*

* ....*

* \q*
--
*Melvin Davidson*
I reserve the right to fantasize. Whether or not you
wish to share my fantasy is entirely up to you.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2018-02-02 02:56:45 Create schema with in a specific database from a script file
Previous Message Abhra Kar 2018-02-02 02:42:33 Re: Create schema with in a specific database from a script file