Re: transactional shared variable in postgresql - Mailing list pgsql-sql

From Rajesh Kumar Mallah
Subject Re: transactional shared variable in postgresql
Date
Msg-id a97c77030611200237s2d5c86dr7b4da34a5386a732@mail.gmail.com
Whole thread Raw
In response to Re: transactional shared variable in postgresql  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-sql
On 11/19/06, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> "Rajesh Kumar Mallah" <mallah.rajesh@gmail.com> writes:
> > In our webapps, we use the same username to connect to the database
> > for all kind of updates. Hence we are not able to makeout whoo modified
> > what . However at application level we have different "userid" for
> different
> > users of the system. we want to somehow pass this "userid"  to the
> databasee
> > server  and accesss it from the triggers that implement the audit
> functions.
>
> Perhaps it would be better to make your "userid" be the actual database
> user?  But anyway, the custom GUC variable facility might serve your
> needs.
> http://www.postgresql.org/docs/8.1/static/runtime-config-custom.html


Dear Tom,

Thanks for the suggestion , it seems to be working.
i used GetConfigOption of guc.c to retrieve the value.
I am setting the variable from psql  eg:
SET general.employee to 101;
I hope what i am doing is correct . I have very little
experience in using C for triggers. can you please tell
if its fine.

in postgresql.conf  i declared.
custom_variable_classes = 'general'

And inside the TRIGGER FUNCTION i use the below

------------ x------------------------ int employee = 0 ;  /* int for holding employee_id */ char *employee_str ; /*
forstoring result for GetConfigOption */
 
 employee_str = (char *) GetConfigOption("general.employee") ;
 if (employee_str != NULL) {   employee = atoi(employee_str); }
-------------x----------------------------

also if i do not cast using (char *) the compiler gives a warning:
audit_trail.c:82: warning: assignment discards qualifiers from pointer
target type
why so?

I have verified that the variable is isolated in transaction and
serves my purpose.

Regards
Mallah.



>
>             regards, tom lane
>


pgsql-sql by date:

Previous
From: Dimitri Fontaine
Date:
Subject: Re: planner used functional index in 7.3.6, now does a seq
Next
From: Tom Lane
Date:
Subject: Re: tsvector_eq appears to be inconsistent.