From: | Steve Atkins <steve(at)blighty(dot)com> |
---|---|
To: | pgsql-general General <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Running a query from the OS CLI |
Date: | 2007-08-08 18:48:07 |
Message-ID: | 170DDB05-F901-4094-94D1-4318540645BB@blighty.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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
From | Date | Subject | |
---|---|---|---|
Next Message | Emi Lu | 2007-08-08 19:18:16 | Dump all objects under a specific schema |
Previous Message | Michael Glaesemann | 2007-08-08 18:42:48 | Re: Running a query from the OS CLI |