Re: Database connectivity using a unix shell

From: Peter Wilson <petew(at)yellowhawk(dot)co(dot)uk>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Database connectivity using a unix shell
Date: 2006-06-29 20:02:06
Message-ID: e81bjs$2m3i$1@news.hub.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Are you just asking random questions? What do you actually want to do? You've
asked how to access Postres from a shell - now you're using 'C'. Are you going
to work your way through Java, Perl and a host of others.

All of this information is *very* clearly available in the manual at:
http://www.postgresql.org/docs/8.1/interactive/index.html

It is an *excellent* manual. Apart from how to access Postgres in a multitude of
ways it includes a good reference on SQL itself.

Go have a read.

Jasbinder Bali wrote:
> 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
> <mailto: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
> <mailto: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

Browse pgsql-general by date

  From Date Subject
Next Message Richard Broersma Jr 2006-06-29 20:06:48 Re: Database connectivity using a unix shell
Previous Message Jasbinder Bali 2006-06-29 19:53:00 Re: Database connectivity using a unix shell