Re: get username of user calling function? - Mailing list pgsql-general

From George Nychis
Subject Re: get username of user calling function?
Date
Msg-id 45E70B04.9040206@cmu.edu
Whole thread Raw
In response to Re: get username of user calling function?  ("A. Kretschmer" <andreas.kretschmer@schollglas.com>)
Responses Re: get username of user calling function?  ("David Legault" <legault.david@gmail.com>)
List pgsql-general

A. Kretschmer wrote:
> You can use the current_user - variable. Select current_user;

I'm trying to create a function in which users can only kill their own processes, it works
perfectly if i hardcode a username in such as this:
CREATE FUNCTION kill_process(integer) RETURNS boolean
AS 'select pg_cancel_backend(procpid)
     FROM (SELECT procpid FROM pg_stat_activity WHERE procpid=$1 and usename=''gnychis'')
AS kill;'
LANGUAGE SQL SECURITY DEFINER;

But if i try to replace usename=''gnychis'' with usename=current_user it no longer works.

Any ideas?

- George

pgsql-general by date:

Previous
From: Vivek Khera
Date:
Subject: Re: How often do I need to reindex tables?
Next
From: Ron Johnson
Date:
Subject: Re: US Highschool database in postgres