4

This is how I am accessing variable in PostgreSQL.

select CURRENT_SETTING('abc.var1')

Is there an optimal way so that I can get default value i.e. 0 in case variable doesn't exist, instead of receiving an error ?

1

1 Answer 1

8

Use the two parameter version of that function (which prevents an error if the variable is missing), then use coalesce():

select coalesce(current_setting('abc.var1', true), '0');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.