Re: Running a query from the OS CLI

Поиск
Список
Период
Сортировка
От Steve Atkins
Тема Re: Running a query from the OS CLI
Дата
Msg-id 170DDB05-F901-4094-94D1-4318540645BB@blighty.com
обсуждение исходный текст
Ответ на Running a query from the OS CLI  ("Gauthier, Dave" <dave.gauthier@intel.com>)
Список 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 по дате отправления:

Предыдущее
От: Michael Glaesemann
Дата:
Сообщение: Re: Running a query from the OS CLI
Следующее
От: "Gauthier, Dave"
Дата:
Сообщение: Re: Running a query from the OS CLI