How to define variables in psql?

From: <kynn(at)panix(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: How to define variables in psql?
Date: 2006-01-31 12:17:17
Message-ID: 200601311217.k0VCHH712178@panix3.panix.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

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!

kj

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Tomka Gergely 2006-01-31 12:51:30 lost archives, alpha data files
Previous Message Sean Davis 2006-01-31 11:57:04 Re: put text list into table form