V
V
Vladimir Korovin2013-06-11 09:57:44
PostgreSQL
Vladimir Korovin, 2013-06-11 09:57:44

passing extra parameters to insert/update postgresql

Good time!
Such a task is worth it - there is a devices table, there is a device_log table. When devices are changed by triggers, an event is written to the log.
Now the task becomes more complicated - we hang editing the values ​​​​partially on the web-muzzle with separation of rights. At the same time, you need to know who performed this or that action. I don’t see the point in writing new functions - triggers in the database do their job perfectly. I would like to pass the $_SESSION['user_id'] parameter to insert/update queries. But how?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
L
lightsgoout, 2013-06-11
@vakorovin

www.stackoverflow.com/a/13172964

A
Andrey, 2013-06-11
@RedOctoberCZ

What is it that bothers you? :)
pg_query($conn, "INSERT INTO device_log (user_id) VALUES ({$_SESSION['user_id']})");

V
Vladimir Korovin, 2013-06-11
@vakorovin

missed

S
simbajoe, 2013-06-11
@simbajoe

You can add a field to devices, like modified_by , that will store the last user who changed the record. Then the user will also be available in the trigger, and it will be possible to add him to the log.

M
mayorovp, 2013-06-11
@mayorovp

You can add a calculated field to the table, which is always NULL, and specify a value for it when inserting records. For INSTEAD OF triggers, in theory, it should work (at least it works in MsSQL).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question