Re: Running a query from the OS CLI - Mailing list pgsql-general

From Steve Atkins
Subject Re: Running a query from the OS CLI
Date
Msg-id 170DDB05-F901-4094-94D1-4318540645BB@blighty.com
Whole thread Raw
In response to Running a query from the OS CLI  ("Gauthier, Dave" <dave.gauthier@intel.com>)
List pgsql-general

On Aug 8, 2007, at 11:13 AM, Gauthier, Dave wrote:

If I have a DB called “foo”

...and...

I want to run “select name from table_a where name like ‘john%’”

...and...

I want no table header “NAME” in the output

...and...

I want to do this as a one-liner from the linux command line

...and...

I don’t want to have to deal with intermediate files or home-grown programs...

Something like this:

psql -A -q  -t -d foo -c “select name from table_a where name like ‘john%’”

You may need to use -U to set a user, and there are a bunch of other
useful flags to set the output format. There are also flags and environment
variables you can set to set the host and port to connect to.

Depending on how your access control permissions are setup you may
need to get a password to psql, typically by using a ~/.pgpass file. Check
the psql man page and the main postgresql docs for the gory details.

Cheers,
  Steve

pgsql-general by date:

Previous
From: Michael Glaesemann
Date:
Subject: Re: Running a query from the OS CLI
Next
From: "Gauthier, Dave"
Date:
Subject: Re: Running a query from the OS CLI