The following documentation comment has been logged on the website: Page: https://www.postgresql.org/docs/18/plpgsql-trigger.html Description: The doc page https://www.postgresql.org/docs/18/plpgsql-trigger.html contains examples of using trigger functions to make an audit table. When SECURITY DEFINER is used in conjunction with SET ROLE it was not clear to me how to store the acting role in the audit table rather than the owner of the trigger function (i.e. current_user, session_user). I found an old mailing list message https://www.postgresql.org/message-id/flat/000801c64143%24313bba50%241e01a8c0%40weasel that suggests using "current_setting('role');", and seems to do exactly what I need. This seems to be little known information as searching the web suggests all sorts of different workarounds for this scenario with BEFORE triggers or creating custom settings. Therefore I suggest this knowledge is rediscovered and mentioned in the official documentation in plpgsql-trigger.html.
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера