Thread: Executing SQL commands in script files
Following reading through all the documentation it is not clear to me how to run a script file containing a number of SQL commands. Presumably I do this through the psql interface but how do I tell it to run a script?
psql < scriptfile.txt
or in a psql console
\i scriptfile.txt
----- Original Message -----From: Susan HoddinottSent: Thursday, February 13, 2003 5:15 AMSubject: [NOVICE] Executing SQL commands in script filesFollowing reading through all the documentation it is not clear to me how to run a script file containing a number of SQL commands. Presumably I do this through the psql interface but how do I tell it to run a script?
You could pipe in the sql commands... eg. % echo "select * from users" | psql userdb On Thu, 2003-02-13 at 15:15, Susan Hoddinott wrote: > Following reading through all the documentation it is not clear to me > how to run a script file containing a number of SQL commands. > Presumably I do this through the psql interface but how do I tell it > to run a script?
Susan, > Following reading through all the documentation it is not clear to me how > to run a script file containing a number of SQL commands. Presumably I do > this through the psql interface but how do I tell it to run a script? In PSQL: \i filename From the command line, or from cron: Postgres_dir/bin/psql -U username database < scriptfile Easy as cake! -- Josh Berkus Aglio Database Solutions San Francisco
Anybody can tell me how to generate a script from a postgreSQL db ? Thanks in advance, Andrew.
Susan, > Thank you all for your assistance. My script ran (almost) straight away > having followed your advise. Is the psql interface documented anywhere? I > am used to Oracle and my approach seems a bit "hit-and-miss". Sometimes > Oracle commands work and sometimes they don't! You could try buying a book on PostgreSQL, hmmm? http://techdocs.postgresql.org/techdocs/bookreviews.php http://www.us.postgresql.org/books/index.html -- Josh Berkus Aglio Database Solutions San Francisco
Andrew...... > Anybody can tell me how to generate a script from a postgreSQL db ? A script to do what? The only script that I can think of to get from a postgreSQL database is the backup datafile made via pg_dump, that's a script to restore the database. We need more information. brew