Check for value with current_setting()

后端 未结 2 1554
轮回少年
轮回少年 2021-02-18 17:57

I\'m trying to work with current_setting().

I came up with this:

CREATE OR REPLACE FUNCTION process_audit() RETURNS TRIGGER AS $audit$
    D         


        
2条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-18 17:58

    9.6 and newer:

    PostgreSQL (9.6+) supports current_setting('setting_name', 't') to fetch a setting and return NULL if it's unset. you can combine this with coalesce to supply a default.

    9.5 and older:

    Per the question, you can do it with a plpgsql function that uses a BEGIN ... EXCEPTION handler, if you don't mind the performance hit and clumsiness. But there's no built-in support.

提交回复
热议问题