Loading a list of SQL scripts with relative paths - Mailing list pgsql-general

From Michael Glaesemann
Subject Loading a list of SQL scripts with relative paths
Date
Msg-id be68ecd71d2689ac5dbfd18541b65eb6@myrealbox.com
Whole thread Raw
Responses Re: Loading a list of SQL scripts with relative paths
Re: Loading a list of SQL scripts with relative paths
List 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


pgsql-general by date:

Previous
From: "Jimmie H. Apsey"
Date:
Subject: pg_dump fails on 7.4 Postgres
Next
From: "Jim C. Nasby"
Date:
Subject: Re: [PERFORM] "Hash index" vs. "b-tree index" (PostgreSQL