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@g2switchworks.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@g2switchworks.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.
>