How to define variables in psql scripts?

From: "Kynn Jones" <kynnjo(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: How to define variables in psql scripts?
Date: 2006-01-30 17:00:02
Message-ID: 1138640402.364100.52260@g47g2000cwa.googlegroups.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

<< kj314159265358979 >>

I know that one can store multiple psql commands and SQL statements in
a separate "script" file, and then "source" the script file, e.g. with
the \i command.

My question is, can I define variables in such a script file? E.g. can
I do something like the following unix-shell-like script?

-- beginning of script

DB=frobozz
DIR=/foo/bar/baz/quux

\c $frobozz
\i "$DIR/other_script.sql"
\i "$DIR/one_more_script.sql"
\i "$DIR/yas.sql"

\echo "done with $DB"

-- end of script

Thanks!

kj314159265358979

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alexander Farber 2006-01-30 17:02:58 How to change the default database for a user
Previous Message Rick Gigger 2006-01-30 16:41:05 Re: postgresql performace degrading after a while