Check for value with current_setting()

你离开我真会死。 提交于 2019-12-03 22:30:24

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.

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

user_id := current_setting('hws.current_user_id')::integer;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!