Problem running script

Started by Sushma Sagaramover 17 years ago6 messagesgeneral
Jump to latest
#1Sushma Sagaram
sushma.2276@gmail.com

My requirement is to write a query in a file read the input from that file
run in postgresql and write the output(query results) into a file. I'm not
able to sue combination of \i and \o
Let' say I have file test.sql and in test.sql I write
select * from abc;

Now I need to read the query from the file and write the output to a file. I
tried
=>\i test.sql \o test

but this is not working. can any one tell me how to do this. I also need to
put my file in a place which can run the file at particualr time of the
day(like cron tab). Where do I put my file?

Regards,
sushma

#2Guillaume Lelarge
guillaume@lelarge.info
In reply to: Sushma Sagaram (#1)
Re: Problem running script

Sushma Sagaram a �crit :

My requirement is to write a query in a file read the input from that
file run in postgresql and write the output(query results) into a file.
I'm not able to sue combination of \i and \o
Let' say I have file test.sql and in test.sql I write
select * from abc;

Now I need to read the query from the file and write the output to a
file. I tried
=>\i test.sql \o test

=> \o test
and then
=> \i test.sql

But this is not related to pgadmin. You should have ask on pgsql-general.

--
Guillaume.
http://www.postgresqlfr.org
http://dalibo.com

#3Sushma Sagaram
sushma.2276@gmail.com
In reply to: Guillaume Lelarge (#2)

My requirement is
1) to write a query in a file, read the input from that file, run in
postgresql and write the output(query results) into a file. I'm not able to
use combination of \i and \o
Let' say I have file test.sql and in test.sql I write
select * from abc;
Now I need to read the query from the file and write the output to a file.
I tried
=>\i test.sql \o test
but that is not working. I want to write a script which reads query from
file and write output in a file and I want to do everything in one script
and run it background at a particular time of teh day.
2) How do I run scripts in postgresql? How do I set the shell and execute
the script?

Regards,
Sushma

#4Ian Lea
ian.lea@gmail.com
In reply to: Sushma Sagaram (#3)
Re: Problem running script

If you are on unix just run

$ psql -whatever < test.sql > test.log

Don't know about Windows.

--
Ian.

Show quoted text

On Fri, Jul 25, 2008 at 6:20 PM, Sushma Sagaram <sushma.2276@gmail.com> wrote:

My requirement is
1) to write a query in a file, read the input from that file, run in
postgresql and write the output(query results) into a file. I'm not able to
use combination of \i and \o
Let' say I have file test.sql and in test.sql I write
select * from abc;
Now I need to read the query from the file and write the output to a file.
I tried
=>\i test.sql \o test
but that is not working. I want to write a script which reads query from
file and write output in a file and I want to do everything in one script
and run it background at a particular time of teh day.
2) How do I run scripts in postgresql? How do I set the shell and execute
the script?

Regards,
Sushma

#5Francisco Reyes
lists@stringsutils.com
In reply to: Ian Lea (#4)
Re: Problem running script

On 9:50 am 07/30/08 "Ian Lea" <ian.lea@gmail.com> wrote:

$ psql -whatever < test.sql > test.log

Also
psql -f <filename> > test.log
Almost the same as above..

=>\i test.sql \o test

That would be wrong.
Say you had test.sql
select * from mytable;

You can change test.sql to:
\o test.log
select * from mytable;

Then you could do \i test.sql and accomplish what you are trying to do.

If your DB has passwords enable you may need to put the user/password combo
in .pgpass.

#6Ragnar
gnari@hive.is
In reply to: Sushma Sagaram (#3)
Re: Problem running script

On f�s, 2008-07-25 at 10:20 -0700, Sushma Sagaram wrote:

My requirement is
1) to write a query in a file, read the input from that file, run in
postgresql and write the output(query results) into a file. I'm not
able to use combination of \i and \o

see psql --help

in particular the options -f , -c and -o

gnari