Re: Database connectivity using a unix shell

From: "Jasbinder Bali" <jsbali(at)gmail(dot)com>
To: "Scott Marlowe" <smarlowe(at)g2switchworks(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Database connectivity using a unix shell
Date: 2006-06-29 19:53:00
Message-ID: a47902760606291253t6205ce11qfe970d5f5d2288aa@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

What if I don't have a shell script and instead of that I have a C code and
need to connect to the postgres database.
How do i accomplish this? do i still need to call this psql clinet interface
or there is some other way to do it..

~Jas

On 6/29/06, Scott Marlowe <smarlowe(at)g2switchworks(dot)com> wrote:
>
> On Thu, 2006-06-29 at 13:29, Jasbinder Bali wrote:
> > this is what i've included in my shell script
> >
> > query="select * from films";
> > a=`echo $query|psql -tq postgres`;
> >
> >
> > it gives an error:
> > role root doesn't exist.
> >
> > where do i have to specify the role?
>
> OK, unless this script NEEDS to be run as root, it's a good idea to run
> it as an unprivaledged account. Create a new one if you can. If it has
> to be run as root, so be it.
>
> You use -U, so it'd look like:
>
> a=`echo $query|psql -tqU myname postgres`;
>
> then you need a password in ~/.pgpass following the format I posted in
> the previous message, unless your server is running in trust mode, in
> which case you don't need to worry about the .pgpass file.
>
> >
> > On 6/29/06, Scott Marlowe <smarlowe(at)g2switchworks(dot)com> wrote:
> > On Thu, 2006-06-29 at 11:29, Jasbinder Bali wrote:
> > > isn't my normal bash script different from psql.
> > > In a bash script how wud u specify the db parameters
> >
> > Look at how I'm doing it here:
> >
> > > > > query="select * from sometable";
> > > > > a=`echo $query|psql -tq dbname`;
> >
> > Note that I'm calling psql from within a bash script. So, the
> > connection
> > params are the same as for psql, cause that's what I'm using.
> >
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Peter Wilson 2006-06-29 20:02:06 Re: Database connectivity using a unix shell
Previous Message elein 2006-06-29 18:37:53 Re: Database connectivity using a unix shell