How to change the default delimiter in PostgreSQL 9.1.9 using SET?
This:

`IF position ('|' in var) IS NOT NULL`


is assuming that the result of position('|' in 'nopipes') is NULL. It is not, it's zero. position returns null only on null input.

regress=&gt; select position('|' in 'abc|def|ghi');
 position 
----------
        4
(1 row)

regress=&gt; select position('|' in 'abcdefghi');
 position 
----------
        0
(1 row)

regress=&gt; select position('|' in null);
 position 
----------

(1 row)


... so if you instead wrote:

IF position ('|' in var) &lt;&gt; 0


it should work fine.

The field separator \f in psql is irrelevant to this. It's only used to control how psql displays result sets. The server and functions on the server cannot see or be affected by this value. \f is just shorthand for \pset fieldsep, it's a psql-local control to choose the field separator for unaligned output:

regress=&gt; \pset format unaligned
Output format is unaligned.
regress=&gt; SELECT 1,2,3;
?column?|?column?|?column?
1|2|3
(1 row)
regress=&gt; \pset fieldsep #
Field separator is "#".
regress=&gt; SELECT 1,2,3;
?column?#?column?#?column?
1#2#3
(1 row)