![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
|
Hi, |
|
I wrote a trigger which writes all changes in a table to a history table (user, time, table, column, oldvalue, newvalue). It works good, but here is one problem: |
|
I use one database user, and the application has its own user management. Of course the history table should contain the userid of my application, since I want to know who did the changes. How can I get the current application-user id into my trigger? Could this be done with a temporary table? Or can you set session variables, which can be accessed inside the trigger? |
#2
| |||
| |||
|
|
begin Thomas Guettler schrieb: Hi, Hi Thomas, how are you? |
|
Maybe a solution: define a custom variable in your postgresql.conf like this: #custom_variable_classes = '' # list of custom variable class names custom_variable_classes = 'myvar' myvar.benutzer = 'foo' Reload your configuration, now you can do this: test=*# set myvar.benutzer = 'foobarbatz'; SET test=*# select current_setting('myvar.benutzer'); current_setting ----------------- foobarbatz (1 row) |
#3
| |||
| |||
|
|
Andreas Kretschmer schrieb: begin Thomas Guettler schrieb: BTW, we can meet at http://www.linux-info-tag.de/ (Sat 3. Nov) I am going to hold one workshop (python programming (for beginners)) and one talk about django (python web framework (which I use with postgres)). I hope we can meat us there. |
|
Maybe a solution: Thank you very much. This is what I was looking for. |
![]() |
| Thread Tools | |
| Display Modes | |
| |