Re: database "cdf_100_1313" does not exist

From: nikhil raj <nikhilraj474(at)gmail(dot)com>
To: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Rob Sargent <robjsargent(at)gmail(dot)com>, Dan Livingston <danlivingstone(at)gmail(dot)com>, Karsten Hilbert <Karsten(dot)Hilbert(at)gmx(dot)net>, pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: database "cdf_100_1313" does not exist
Date: 2019-09-09 14:38:51
Message-ID: CAG1ps1yJFD1kCBGk4pMyN-BupTs+ii0mjPLRbbcxsELqZFQHzw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi Adrian,

DBLIST=/usr/lib/postgresql/11/bin/psql -p 5432 -U postgres -d postgres -q
-t -c "SELECT datname from pg_database where datname in
('CDF_100_1313')"/usr/lib/postgresql/11/bin/psql
-p 5432 -U postgres -d $DBLIST -c "GRANT CONNECT ON DATABASE \"$DBLIST\" TO
cpupdate"
only in the grant its taking space rest in -d its perfectly all right.

On Mon, Sep 9, 2019 at 8:04 PM Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
wrote:

> On 9/9/19 7:30 AM, nikhil raj wrote:
> > Hi All,
> >
> > just did few modification of the shell command still having the same
> > issue. Having the issue with the Grant command only its not taking the
> > parameters.
> >
> > /usr/lib/postgresql/11/bin/psql -p 5432 -U postgres -d $DBLIST -c
> > "GRANT CONNECT ON DATABASE \"$DBLIST\" TO cpupdate"
> > ERROR: database " CDF_100_1313" does not exist
>
> You are not showing how you are currently generating DBLIST. From the
> looks of it you have a leading space in the database name:
>
> " CDF_100_1313"
>
>
> > *
> > *
> > *** For the above one we have its taking space in the Databases name
> > starting.*
> >
> > /usr/lib/postgresql/11/bin/psql -p 5432 -U postgres -d $DBLIST -c "GRANT
> > CONNECT ON DATABASE "$DBLIST" TO cpupdate"
> > psql: warning: extra command-line argument "ASD_100_1313 TO cpupdate"
> > ignored
> > ERROR: syntax error at end of input
> > LINE 1: GRANT CONNECT ON DATABASE
> > ^
> >
> >
> >
> > On Mon, Sep 9, 2019 at 7:47 PM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us
> > <mailto:tgl(at)sss(dot)pgh(dot)pa(dot)us>> wrote:
> >
> > > On Sep 9, 2019, at 7:16 AM, nikhil raj <nikhilraj474(at)gmail(dot)com
> > <mailto:nikhilraj474(at)gmail(dot)com>> wrote:
> > >> /usr/lib/postgresql/11/bin/psql -p 5432 -U postgres -d $DBLIST
> > -c "GRANT CONNECT ON DATABASE $DBLIST TO cpupdate"
> > >> ERROR: database "cdf_100_1313" does not exist
> >
> > This still isn't quoted properly. It's tricky since double-quote is
> > special to both the shell and SQL. You need something like
> >
> > /usr/lib/postgresql/11/bin/psql -p 5432 -U postgres -d "$DBLIST" -c
> > "GRANT CONNECT ON DATABASE \"$DBLIST\" TO cpupdate"
> >
> > regards, tom lane
> >
>
>
> --
> Adrian Klaver
> adrian(dot)klaver(at)aklaver(dot)com
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Daniel Verite 2019-09-09 14:45:08 Re: database "cdf_100_1313" does not exist
Previous Message Adrian Klaver 2019-09-09 14:34:43 Re: database "cdf_100_1313" does not exist