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