Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- \echo Start functions/WRITE_MESSAGE_TO_TABLE.pg_sql
- /** Write given parameters into the logging table.
- * It is meant to be called in an autonomous transaction to and best done
- * in a separate process to reduce impact on main transaction as much as
- * possible. As colateral the ID of written record is returned.
- *
- * @function WRITE_MESSAGE_TO_TABLE
- * @return bigint ID of written record
- * @param in text I_FUNCTION Value for LOG.FUNCTION.
- * @param in text I_MESSAGE Value for LOG.MESSAGE.
- * @param in text I_LEVEL Value for LOG.LEVEL.
- * @param in name I_PRESENT_USER Value for LOG.PRESENT_USER.
- * @param in name I_SESSION_USER Value for LOG.SESS_USER.
- * @param in timestamp_with_timezone I_TRANSACTION_TIMESTAMP Value for LOG.TRANSACTION_TIMESTAMP.
- * @param in bigint I_TRANSACTION_ID Value for LOG.TRANSACTION_ID.
- * @param in bigint I_SERVER_PID Value for LOG.SERVER_PID.
- * @param in inet I_REMOTE_ADDRESS Value for LOG.REMOTE_ADDRESS.
- * @param in int I_REMOTE_PORT Value for LOG.REMOTE_PORT.
- * @private
- * @info This function is meant to be private. Its use outside pglogger is
- * very limited at most. That's why it is marked as private eventhough
- * it is visible to the outside. All of this is due to the fact that
- * PostgreSQL 10 and earlier does not support packages.
- * @version $Id: WRITE_MESSAGE_TO_TABLE.pg_sql 4 2018-03-30 16:39:10Z thiemo $
- * @todo Once PostgreSQL supports packages, integrate this function into one.
- * For the time being, it should get installed within a schema on its
- * own and no execution grants should be given on it.
- * @todo Once HyperSQL supports a license tag, convert the corresponding
- * info tag into one.
- * @copyright Thiemo Kellner, 2018 -
- * @info License LGPLv3
- * @webpage https://www.sourceforge.net/projects/pglogger
- */
- create or replace function WRITE_MESSAGE_TO_TABLE(
- I_FUNCTION text,
- I_MESSAGE text,
- I_LEVEL text,
- I_PRESENT_USER name,
- I_SESSION_USER name,
- I_TRANSACTION_TIMESTAMP timestamp with time zone,
- I_TRANSACTION_ID bigint,
- I_SERVER_PID bigint,
- I_REMOTE_ADDRESS inet,
- I_REMOTE_PORT int
- )
- returns bigint
- language plpgsql
- volatile as
- $body$
- declare
- V_ID bigint;
- begin
- insert into LOG(
- FUNCTION,
- MESSAGE,
- LEVEL,
- PRESENT_USER,
- SESS_USER,
- TRANSACTION_TIMESTAMP,
- TRANSACTION_ID,
- SERVER_PID,
- REMOTE_ADDRESS,
- REMOTE_PORT
- ) values (
- I_FUNCTION,
- I_MESSAGE,
- I_LEVEL,
- I_PRESENT_USER,
- I_SESSION_USER,
- I_TRANSACTION_TIMESTAMP,
- I_TRANSACTION_ID,
- I_SERVER_PID,
- I_REMOTE_ADDRESS,
- I_REMOTE_PORT
- ) returning ID into V_ID;
- return V_ID;
- end;
- $body$;
- comment on function WRITE_MESSAGE_TO_TABLE(
- I_FUNCTION text,
- I_MESSAGE text,
- I_LEVEL text,
- I_PRESENT_USER name,
- I_SESSION_USER name,
- I_TRANSACTION_TIMESTAMP timestamp with time zone,
- I_TRANSACTION_ID bigint,
- I_SERVER_PID bigint,
- I_REMOTE_ADDRESS inet,
- I_REMOTE_PORT int
- ) is
- 'Write given parameters into the logging table. It is meant to be called in an autonomous transaction to and best done in a separate process to reduce impact on main transaction as much as possible.
- As colateral the ID of written record is returned.
- $Header: svn+ssh://thiemo@svn.code.sf.net/p/pglogger/code/functions/WRITE_MESSAGE_TO_TABLE.pg_sql 4 2018-03-30 16:39:10Z thiemo $';
- commit; -- unlike Oracle not all ddl commit implicitly
- \echo End functions/WRITE_MESSAGE_TO_TABLE.pg_sql
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement