agora inbox for pgsql-sql@postgresql.org  
help / color / mirror / Atom feed
How to get pgsql to echo commands in a command file
4+ messages / 3 participants
[nested] [flat]

* How to get pgsql to echo commands in a command file
@ 2016-04-22 22:50  Michael Moore <michaeljmoore@gmail.com>
  0 siblings, 2 replies; 4+ messages in thread

From: Michael Moore @ 2016-04-22 22:50 UTC (permalink / raw)
  To: pgsql-sql

I log into pgsql and then type:
\i test.sql

test.sql contains a single SELECT command and when I run that file I see
the result of the select command.. The problem is, I also want to see the
SELECT command itself.

I've tried
/echo
/qecho
and a lot of other commands, but nothing works.

What do I need to do in order to see the commands in test.sql as well as
the output of those commands on my pgsql window?

I'm running on Windows 7 if that matters.

TIA,
Mike

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: How to get pgsql to echo commands in a command file
@ 2016-04-22 22:58  David G. Johnston <david.g.johnston@gmail.com>
  parent: Michael Moore <michaeljmoore@gmail.com>
  1 sibling, 0 replies; 4+ messages in thread

From: David G. Johnston @ 2016-04-22 22:58 UTC (permalink / raw)
  To: Michael Moore <michaeljmoore@gmail.com>; +Cc: pgsql-sql

On Fri, Apr 22, 2016 at 3:50 PM, Michael Moore <michaeljmoore@gmail.com>
wrote:

> I log into pgsql and then type:
> \i test.sql
>
> test.sql contains a single SELECT command and when I run that file I see
> the result of the select command.. The problem is, I also want to see the
> SELECT command itself.
>
> I've tried
> /echo
> /qecho
> and a lot of other commands, but nothing works.
>
> What do I need to do in order to see the commands in test.sql as well as
> the output of those commands on my pgsql window?
>
>
​\set ECHO all​
​
The \echo and \qecho commands​ commands only echo their arguments - they do
not effect the environment.  You have to use "\set" or "\pset" (and some
other commands) if you want to affect the environment of subsequent
statements.

Or just invoke psql as "psql --echo-all" - optionally specifying the file
"psql --echo-all -f test.sql"

The documentation is quite good, if a bit long.

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

I'm running on Windows 7 if that matters.
>
>
​That would explain the forward slashes...

​David J.​

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: How to get pgsql to echo commands in a command file
@ 2016-04-22 22:58  Adrian Klaver <adrian.klaver@aklaver.com>
  parent: Michael Moore <michaeljmoore@gmail.com>
  1 sibling, 1 reply; 4+ messages in thread

From: Adrian Klaver @ 2016-04-22 22:58 UTC (permalink / raw)
  To: Michael Moore <michaeljmoore@gmail.com>; pgsql-sql

On 04/22/2016 03:50 PM, Michael Moore wrote:
> I log into pgsql and then type:
> \i test.sql
>
> test.sql contains a single SELECT command and when I run that file I see
> the result of the select command.. The problem is, I also want to see
> the SELECT command itself.
>
> I've tried
> /echo
> /qecho
> and a lot of other commands, but nothing works.

http://www.postgresql.org/docs/9.5/interactive/app-psql.html
"
ECHO

     If set to all, all nonempty input lines are printed to standard 
output as they are read. (This does not apply to lines read 
interactively.) To select this behavior on program start-up, use the 
switch -a. If set to queries, psql prints each query to standard output 
as it is sent to the server. The switch for this is -e. If set to 
errors, then only failed queries are displayed on standard error output. 
The switch for this is -b. If unset, or if set to none (or any other 
value than those above) then no queries are displayed.
"


aklaver@panda:~> cat psql_test.sql
select * from a ;

aklaver@panda:~> psql -a -d test -U  postgres -h localhost
psql (9.4.6)
SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, 
bits: 256, compression: off)
Type "help" for help.

test=# \i psql_test.sql
select * from a ;
  id | v1 | v2 | v3
----+----+----+----
   1 |  2 |  3 |  4
   2 |  2 |  3 |  4
(2 rows)



>
> What do I need to do in order to see the commands in test.sql as well as
> the output of those commands on my pgsql window?
>
> I'm running on Windows 7 if that matters.
>
> TIA,
> Mike


-- 
Adrian Klaver
adrian.klaver@aklaver.com


-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: How to get pgsql to echo commands in a command file
@ 2016-04-22 23:04  Michael Moore <michaeljmoore@gmail.com>
  parent: Adrian Klaver <adrian.klaver@aklaver.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Michael Moore @ 2016-04-22 23:04 UTC (permalink / raw)
  To: Adrian Klaver <adrian.klaver@aklaver.com>; +Cc: pgsql-sql

Thanks guys!

On Fri, Apr 22, 2016 at 3:58 PM, Adrian Klaver <adrian.klaver@aklaver.com>
wrote:

> On 04/22/2016 03:50 PM, Michael Moore wrote:
>
>> I log into pgsql and then type:
>> \i test.sql
>>
>> test.sql contains a single SELECT command and when I run that file I see
>> the result of the select command.. The problem is, I also want to see
>> the SELECT command itself.
>>
>> I've tried
>> /echo
>> /qecho
>> and a lot of other commands, but nothing works.
>>
>
> http://www.postgresql.org/docs/9.5/interactive/app-psql.html
> "
> ECHO
>
>     If set to all, all nonempty input lines are printed to standard output
> as they are read. (This does not apply to lines read interactively.) To
> select this behavior on program start-up, use the switch -a. If set to
> queries, psql prints each query to standard output as it is sent to the
> server. The switch for this is -e. If set to errors, then only failed
> queries are displayed on standard error output. The switch for this is -b.
> If unset, or if set to none (or any other value than those above) then no
> queries are displayed.
> "
>
>
> aklaver@panda:~> cat psql_test.sql
> select * from a ;
>
> aklaver@panda:~> psql -a -d test -U  postgres -h localhost
> psql (9.4.6)
> SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384,
> bits: 256, compression: off)
> Type "help" for help.
>
> test=# \i psql_test.sql
> select * from a ;
>  id | v1 | v2 | v3
> ----+----+----+----
>   1 |  2 |  3 |  4
>   2 |  2 |  3 |  4
> (2 rows)
>
>
>
>
>
>> What do I need to do in order to see the commands in test.sql as well as
>> the output of those commands on my pgsql window?
>>
>> I'm running on Windows 7 if that matters.
>>
>> TIA,
>> Mike
>>
>
>
> --
> Adrian Klaver
> adrian.klaver@aklaver.com
>

^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2016-04-22 23:04 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2016-04-22 22:50 How to get pgsql to echo commands in a command file Michael Moore <michaeljmoore@gmail.com>
2016-04-22 22:58 ` David G. Johnston <david.g.johnston@gmail.com>
2016-04-22 22:58 ` Adrian Klaver <adrian.klaver@aklaver.com>
2016-04-22 23:04   ` Michael Moore <michaeljmoore@gmail.com>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox