From: | Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at> |
---|---|
To: | a <372660931(at)qq(dot)com>, pgsql-general <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Is it possible to get username information while writing trigger? |
Date: | 2018-05-07 07:57:20 |
Message-ID: | 1525679840.2414.3.camel@cybertec.at |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
a wrote:
> What I want is to add a log entry at the last column of each row, which will record the
> history update, insert automatically when relative statement is processed.
>
> I have read the documentation on triggers, which helps a lot. However, I may have few
> more extra requirement to complete my wishes:
>
> 1, I would like to get the username of who executed the statement;
>
> 2, I would like to get the column name that is being updated;
>
> If it is possible and how should I do it??
You could use the "current_user" function to get the current user.
Mind, however, that updates caused by a cascading update from a
foreign key constraint will be executed as the owner of the table,
so it would be better to use "session_user" to avoid surprises.
You cannot get the column name, because PostgreSQL updates a whole row,
not an individual column. The best you can do is to check which
column values are different in OLD and NEW.
Yours,
Laurenz Albe
--
Cybertec | https://www.cybertec-postgresql.com
From | Date | Subject | |
---|---|---|---|
Next Message | a | 2018-05-07 08:39:41 | Re: Is it possible to get username information while writingtrigger? |
Previous Message | a | 2018-05-07 07:39:37 | Is it possible to get username information while writing trigger? |