Sunday, November 24, 2013

Custom Variables in Postgres

--set a session variable
set mycustom.var = 'value';

--display it
show mycustom.var; 

--use it
select * from mytable where some_column = current_setting('mycustom.var');

For PG 9.1 or earlier, you would have to add/change this in postgresql.conf:

custom_variable_classes = 'mycustom[,...]'

Restart or SELECT pg_reload_conf();

No comments: