In the previous recipe, we have seen how to use the ON_ERROR_STOP variable. Here we show how to work with any variable, including user-defined ones.
As an example, we create a script that does some work on a given table. We will keep it simple, because we just want to show how variables work.
For instance, we might want to add a text column to a table, and then set it to a given value. So we write the following lines into a file called vartest.sql :
ALTER TABLE mytable ADD COLUMN mycol text;
UPDATE mytable SET mycol = 'myval';
The script can be run as follows:
psql -f vartest.sql