Re: Running a query from the OS CLI

From: "Dann Corbit" <DCorbit(at)connx(dot)com>
To: "Gauthier, Dave" <dave(dot)gauthier(at)intel(dot)com>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: Running a query from the OS CLI
Date: 2007-08-08 18:38:19
Message-ID: D425483C2C5C9F49B5B7A41F8944154701000836@postal.corporate.connx.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

See:

http://www.postgresql.org/docs/8.2/interactive/app-psql.html

________________________________

From: pgsql-general-owner(at)postgresql(dot)org
[mailto:pgsql-general-owner(at)postgresql(dot)org] On Behalf Of Gauthier, Dave
Sent: Wednesday, August 08, 2007 11:14 AM
To: pgsql-general(at)postgresql(dot)org
Subject: [GENERAL] Running a query from the OS CLI

If I have a DB called "foo"
>>

-d dbname
--dbname dbname

Specifies the name of the database to connect to. This is equivalent to
specifying dbname as the first non-option argument on the command line.

<<

...and...

I want to run "select name from table_a where name like 'john%'"

>>

-c command
--command command

Specifies that psql is to execute one command string, command, and then
exit. This is useful in shell scripts.

command must be either a command string that is completely parsable by
the server (i.e., it contains no psql specific features), or a single
backslash command. Thus you cannot mix SQL and psql meta-commands with
this option. To achieve that, you could pipe the string into psql, like
this: echo '\x \\ SELECT * FROM foo;' | psql. (\\ is the separator
meta-command.)

If the command string contains multiple SQL commands, they are processed
in a single transaction, unless there are explicit BEGIN/COMMIT commands
included in the string to divide it into multiple transactions. This is
different from the behavior when the same string is fed to psql's
standard input.

<<

...and...

I want no table header "NAME" in the output

>>

-t
--tuples-only

Turn off printing of column names and result row count footers, etc.
This is equivalent to the \t command.

<<

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

Is this possible?

>>

Read The Fine Manual.

<<

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Michael Glaesemann 2007-08-08 18:42:48 Re: Running a query from the OS CLI
Previous Message Oleg Bartunov 2007-08-08 18:28:07 Re: Dealing with tsvector in fuctions for data split