Description:
With the introduction of version 8.21, capability is added for a user ATTRIBUTE field containing a JSON object (see CREATE USER and ALTER USER). It would be useful to retrieve this ATTRIBUTE in a simple and straightforward manner using the user() and current_user() functions. This would also enable ANY of this information to be extracted and used in a single simple expression in both GENERATED columns and DEFAULT column expressions.
How to repeat:
Invoke user() or current_user() function. There is currently no option to return the ATTRIBUTE information.
Suggested fix:
Recommend the user() and current_user() functions be modified with an optional flag that, when set, would return both the USER/HOST information and ATTRIBUTE JSON object as a single JSON object. For example, invoking user(attribute_flag)with attribute_flag set would return a JSON object consisting of the USER and HOST keys prepended to any existing ATTRIBUTE JSON object.
As an example, for a user jim@localhost with an ATTRIBUTE value of {"fname": "James", "lname": "Scott", "phone": "123-456-7890"}, invoking the user() function as user(1) would return {"USER": "jim", "HOST": "localhost", "fname": "James", "lname": "Scott", "phone": "123-456-7890"}. If no ATTRIBUTE exists for jim@localhost, then user(1) would return {"USER": "jim", "HOST": "localhost"}.