You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In this audit table you can opt to store exactly one row. One can
ensure this by running the following as a unit:
TRUNCATE audit; INSERT INTO audit VALUES (5, 'daniel');
Then, one can change the trigger to reference that table.
That's the gist of it. Here are embellishments and additional
thoughts that may involve more invasive but also potentially helpful
changes to the module:
TRUNCATE is scary, because it deletes everything in a
table. One should take pains to ensure that one does not truncate
an important table.
To avoid truncate table and get some potentially useful behavior,
consider CREATE TEMPORARY TABLE ... ON COMMIT DELETE ROWS; This
causes the audit table to be depopulated on every COMMIT; which may
help prevent error.
Another that is interesting is CREATE TEMPORARY TABLE ... ON COMMIT
DROP;. The downside is that temporary table creation tends be a bit
more expensive than temporary table truncation.
A slightly different approach would be to use CREATE OR REPLACE
FUNCTION in the pg_temp namespace, which has the effect of creating a
'temporary function'.
The text was updated successfully, but these errors were encountered:
As suggested by Heroku's database staff:
CREATE TEMPORARY TABLE audit (user_id integer, user_name text);
In this audit table you can opt to store exactly one row. One can
ensure this by running the following as a unit:
TRUNCATE audit; INSERT INTO audit VALUES (5, 'daniel');
Then, one can change the trigger to reference that table.
That's the gist of it. Here are embellishments and additional
thoughts that may involve more invasive but also potentially helpful
changes to the module:
table. One should take pains to ensure that one does not truncate
an important table.
consider CREATE TEMPORARY TABLE ... ON COMMIT DELETE ROWS; This
causes the audit table to be depopulated on every COMMIT; which may
help prevent error.
DROP;. The downside is that temporary table creation tends be a bit
more expensive than temporary table truncation.
FUNCTION in the pg_temp namespace, which has the effect of creating a
'temporary function'.
The text was updated successfully, but these errors were encountered: