Home > Software engineering >  function current_user
function current_user

Time:11-03

How can I create a function that shows only the OID of the connected user? In this case you only have to display the number 10 when calling the function

enter image description here

postgres=# select current_user;
 current_user 
--------------
 postgres
(1 fila)

In this case you only have to display the number 10 when calling the function

CodePudding user response:

You can look it up in pg_roles:

CREATE FUNCTION current_userid() RETURNS oid
   STABLE PARALLEL SAFE LANGUAGE sql AS
'SELECT oid FROM pg_roles WHERE rolname = current_user';
  • Related