Re: get username of user calling function?

From: George Nychis <gnychis(at)cmu(dot)edu>
To: "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: get username of user calling function?
Date: 2007-03-01 17:19:00
Message-ID: 45E70B04.9040206@cmu.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ron Johnson 2007-03-01 17:21:09 Re: US Highschool database in postgres
Previous Message Vivek Khera 2007-03-01 17:10:06 Re: How often do I need to reindex tables?