How to find out who is calling the function

Started by BARTKO, Zoltanalmost 22 years ago4 messagesgeneral
Jump to latest
#1BARTKO, Zoltan
bartko.zoltan@pobox.sk

Dear friends,

I had a look at www.pgsql.ru, looking for how to find out what user is calling the function - from inside the function. No luck.

Could someone enlighten me:

I have a stored function. I want to do the following:

if caller() = ''userA'' then
return -1; -- error
else
return 0;
end if; -- OK

caller() is the function I am looking for. Is there any function like this? If not, is there a way how to write one?

Thanks

Zoltan

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: BARTKO, Zoltan (#1)
Re: How to find out who is calling the function

"BARTKO Zoltan" <bartko.zoltan@pobox.sk> writes:

caller() is the function I am looking for.

The closest thing you will find is SESSION_USER.

regards, tom lane

#3Bruce Momjian
bruce@momjian.us
In reply to: Tom Lane (#2)
Re: How to find out who is calling the function

Tom Lane <tgl@sss.pgh.pa.us> writes:

"BARTKO Zoltan" <bartko.zoltan@pobox.sk> writes:

caller() is the function I am looking for.

The closest thing you will find is SESSION_USER.

I think you can have to have a trigger that compared session_user with the
value of the column in OLD and blocked the update/delete if it doesn't match.

--
greg

#4Duane Lee - EGOVX
DLee@mail.maricopa.gov
In reply to: Bruce Momjian (#3)
Re: How to find out who is calling the function

Why not use CURRENT_USER?

-----Original Message-----
From: BARTKO Zoltan [mailto:bartko.zoltan@pobox.sk]
Sent: Friday, June 04, 2004 10:34 PM
To: pgsql-general@postgresql.org
Subject: [GENERAL] How to find out who is calling the function

Dear friends,

I had a look at www.pgsql.ru <http://www.pgsql.ru&gt; , looking for how to find
out what user is calling the function - from inside the function. No luck.

Could someone enlighten me:

I have a stored function. I want to do the following:

if caller() = ''userA'' then
return -1; -- error
else
return 0;
end if; -- OK

caller() is the function I am looking for. Is there any function like this?
If not, is there a way how to write one?

Thanks

Zoltan