Loading a list of SQL scripts with relative paths

From: Michael Glaesemann <grzm(at)myrealbox(dot)com>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Loading a list of SQL scripts with relative paths
Date: 2005-05-10 15:24:49
Message-ID: be68ecd71d2689ac5dbfd18541b65eb6@myrealbox.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello,

I often test SQL in separate text files, loading them into the server
using psql -d -f from the command line, wrapping the SQL in a BEGIN;
... ROLLBACK; transaction until I'm sure it does what I want. Often the
SQL script is just a small part of a larger chunk of work I'm doing on
the development server, so I'll have a number of these files that I'll
want to apply to the production server at a single time. I've been
trying to figure out an efficient way to load all of the scripts
together.

One option is to copy all of the scripts into one file, which I have
done on occasion. What I've been doing more recently is making an
additional file that uses \i to call the other files, for example

\i /path/to/script1
\i /path/to/script2
\i /path/to/script3

This works well, but I think I'll have to change all of the paths when
I move the group of scripts to the production server to load them. What
I'd like to do is be able to use paths relative to the file that
contains the \i commands. This doesn't seem to work when using \i.

I imagine that I'm not alone in wanting to load a bunch of scripts at a
go, and I'm wondering how others handle this situation. Advice?
Suggestions? What works for you?

Michael Glaesemann
grzm myrealbox com

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jim C. Nasby 2005-05-10 15:32:45 Re: [PERFORM] "Hash index" vs. "b-tree index" (PostgreSQL
Previous Message Jimmie H. Apsey 2005-05-10 15:07:06 pg_dump fails on 7.4 Postgres