psql output result

Started by Tiffany Thangabout 8 years ago4 messagesgeneral
Jump to latest
#1Tiffany Thang
tiffanythang@gmail.com

Hi,
I have a SQL script that does some DDLs, inserts and counts.

The command I ran is
psql dbname -c "\i crscript.sql" > output.txt

In output.txt, I got something like
INSERT 0 1
INSERT 0 1
CREATE TABLE
INSERT 0 2
count
-------
9
(1 row)

Is there a way to output the SQLs and DDLs so that I could easily identify
what statements were executed?

Thanks.

#2Geoff Winkless
pgsqladmin@geoff.dj
In reply to: Tiffany Thang (#1)
Re: psql output result

On 15 March 2018 at 14:57, Tiffany Thang <tiffanythang@gmail.com> wrote:

Is there a way to output the SQLs and DDLs so that I could easily identify
what statements were executed?

-a, --echo-all echo all input from script

Geoff​

#3Adrian Klaver
adrian.klaver@aklaver.com
In reply to: Tiffany Thang (#1)
Re: psql output result

On 03/15/2018 07:57 AM, Tiffany Thang wrote:

Hi,
I have a SQL script that does some DDLs, inserts and counts.

The command I ran is
psql dbname -c "\i crscript.sql" > output.txt

In output.txt, I got something like
INSERT 0 1
INSERT 0 1
CREATE TABLE
INSERT 0 2
 count
-------
     9
(1 row)

Is there a way to output the SQLs and DDLs so that I could easily
identify what statements were executed?

aklaver@tito:~> psql -d test -U aklaver -a -f sql_test.sql
\pset null 'NULL'
Null display is "NULL".
CREATE TABLE tbl_test(fld_1 int, fld_2 varchar);
CREATE TABLE
INSERT INTO tbl_test VALUES (1, 'dog'), (2, 'cat');
INSERT 0 2
DROP TABLE tbl_test;
DROP TABLE

Thanks.

--
Adrian Klaver
adrian.klaver@aklaver.com

#4Tiffany Thang
tiffanythang@gmail.com
In reply to: Adrian Klaver (#3)
Re: psql output result

Thanks Geoff and Adrian!

On Thu, Mar 15, 2018 at 11:03 AM, Adrian Klaver <adrian.klaver@aklaver.com>
wrote:

Show quoted text

On 03/15/2018 07:57 AM, Tiffany Thang wrote:

Hi,
I have a SQL script that does some DDLs, inserts and counts.

The command I ran is
psql dbname -c "\i crscript.sql" > output.txt

In output.txt, I got something like
INSERT 0 1
INSERT 0 1
CREATE TABLE
INSERT 0 2
count
-------
9
(1 row)

Is there a way to output the SQLs and DDLs so that I could easily
identify what statements were executed?

aklaver@tito:~> psql -d test -U aklaver -a -f sql_test.sql
\pset null 'NULL'
Null display is "NULL".
CREATE TABLE tbl_test(fld_1 int, fld_2 varchar);
CREATE TABLE
INSERT INTO tbl_test VALUES (1, 'dog'), (2, 'cat');
INSERT 0 2
DROP TABLE tbl_test;
DROP TABLE

Thanks.

--
Adrian Klaver
adrian.klaver@aklaver.com