How to change the default delimiter in PostgreSQL 9.1.9 using SET? From within a bash script I tried to use a replace and a detection on a field containing a pipe like:

IF position ('|' in var) IS NOT NULL THEN ...

...REPLACE(field, '|', '#') 


The data itself was loaded into the DB using the COPY statement e.g. 

COPY records FROM '$datasource' WITH DELIMITER AS ',' CSV HEADER NULL as '';


I am using psql (9.1.9) and the default field separator is pipe:

#&gt; \f
#&gt; Field separator is "|".


Ideally I would like to SET the default limiter in a CREATE OR REPLACE function at runtime like:

...
END; \$\$ LANGUAGE plpgsql SET config_param TO '#';


OR as a seperate statement just like
    SET config_param TO '#';

I searched the documentation and internet for the right name of the config parameter without luck. Any help appreciated.
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)