Check for value with current_setting()

后端 未结 2 1562
轮回少年
轮回少年 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.

    0 讨论(0)
  • 2021-02-18 18:07

    Shouldn't you also make a cast? As follows,

    user_id := current_setting('hws.current_user_id')::integer;
    
    0 讨论(0)
提交回复
热议问题