Re: get username of user calling function?

From: "David Legault" <legault(dot)david(at)gmail(dot)com>
To: "George Nychis" <gnychis(at)cmu(dot)edu>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: get username of user calling function?
Date: 2007-03-01 17:30:18
Message-ID: e0b20d410703010930s7a58e6fdi475cb9c13bae3637@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 3/1/07, George Nychis <gnychis(at)cmu(dot)edu> wrote:
>
>
>
> 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;

See the EXECUTE function in the pl/pgSQL language in the docs for dynamic
queries.

But if i try to replace usename=''gnychis'' with usename=current_user it no
> longer works.
>
> Any ideas?
>
> - George
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faq
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bill Moran 2007-03-01 17:33:52 Re: supporting 2000 simultaneous connections.
Previous Message MargaretGillon 2007-03-01 17:24:16 Re: PG periodic Error on W2K