Thread: Executing SQL commands in script files

Executing SQL commands in script files

From
"Susan Hoddinott"
Date:
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?

Re: Executing SQL commands in script files

From
"Andres Ledesma"
Date:
psql < scriptfile.txt
 
    or in a psql console
 
\i scriptfile.txt
 
----- Original Message -----
Sent: Thursday, February 13, 2003 5:15 AM
Subject: [NOVICE] 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?

Re: Executing SQL commands in script files

From
simran
Date:
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?


Re: Executing SQL commands in script files

From
Josh Berkus
Date:
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

Re: Generating the db script file ....

From
"Andres Ledesma"
Date:
Anybody can tell me how to generate a script from a postgreSQL db ?

Thanks in advance,

Andrew.





Re: Executing SQL commands in script files

From
Josh Berkus
Date:
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

Re: Generating the db script file ....

From
brew@theMode.com
Date:
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