Thread: question: how to preload data and excute table creation scripts
Hi, I guess is simple, but cannot find out how to run scripts in psql( Linux) What I would like to do is following: 1. Create a table structure from scripts ? 2. Preload data to remote Linux box (IP added to conf file) Thanks, Mark __________________________________ Do you Yahoo!? Yahoo! Mail - Helps protect you from nasty viruses. http://promotions.yahoo.com/new_mail
On Wed, Dec 08, 2004 at 08:58:49AM -0800, Mark wrote: > I guess is simple, but cannot find out how to run scripts in psql( > Linux) Create a file with the SQL statements you'd like to run. There are several ways to get psql to read the file: Redirection: psql < foo.sql Command-line option: psql -f foo.sql Include into the current psql session: psql \i foo.sql See the psql documentation for more info. > What I would like to do is following: > > 1. Create a table structure from scripts ? > 2. Preload data to remote Linux box (IP added to conf file) See above. For bulk loads, consider using COPY instead of INSERT since COPY is faster. You can find additional advice in the "Populating a Database" section of the "Performance Tips" chapter in the PostgreSQL documentation. Consider using transactions in your script -- that way if you make a mistake and psql raises an error, you're not left with the work half done. See also the ON_ERROR_STOP variable in the psql documentation. -- Michael Fuhr http://www.fuhr.org/~mfuhr/
On Wed, Dec 08, 2004 at 08:58:49 -0800, Mark <sendmailtomark@yahoo.com> wrote: > Hi, > > I guess is simple, but cannot find out how to run scripts in psql( > Linux) > > What I would like to do is following: > > 1. Create a table structure from scripts ? > 2. Preload data to remote Linux box (IP added to conf file) You can use psql to do things like this. psql < ddl.sql psql < copy.sql (Where dd.sql holds the ddl creation commands and copy.sql holds the copy commands to load the data. You can look at pg_dump output for examples.)