macro_rules! ereport {
(ERROR, $errcode:expr, $message:expr $(, $detail:expr)? $(,)?) => { ... };
(PANIC, $errcode:expr, $message:expr $(, $detail:expr)? $(,)?) => { ... };
(FATAL, $errcode:expr, $message:expr $(, $detail:expr)? $(,)?) => { ... };
(WARNING, $errcode:expr, $message:expr $(, $detail:expr)? $(,)?) => { ... };
(NOTICE, $errcode:expr, $message:expr $(, $detail:expr)? $(,)?) => { ... };
(INFO, $errcode:expr, $message:expr $(, $detail:expr)? $(,)?) => { ... };
(LOG, $errcode:expr, $message:expr $(, $detail:expr)? $(,)?) => { ... };
(DEBUG5, $errcode:expr, $message:expr $(, $detail:expr)? $(,)?) => { ... };
(DEBUG4, $errcode:expr, $message:expr $(, $detail:expr)? $(,)?) => { ... };
(DEBUG3, $errcode:expr, $message:expr $(, $detail:expr)? $(,)?) => { ... };
(DEBUG2, $errcode:expr, $message:expr $(, $detail:expr)? $(,)?) => { ... };
(DEBUG1, $errcode:expr, $message:expr $(, $detail:expr)? $(,)?) => { ... };
($loglevel:expr, $errcode:expr, $message:expr $(, $detail:expr)? $(,)?) => { ... };
}
Expand description
Sends some kind of message to Postgres, and if it’s a PgLogLevel::ERROR or greater, Postgres’ error handling takes over and, in the case of PgLogLevel::ERROR, aborts the current transaction.
This macro is necessary when one needs to supply a specific SQL error code as part of their error message.
The argument order is:
log_level: [PgLogLevel]
error_code: [PgSqlErrorCode]
message: String
- (optional)
detail: String
§Examples
ereport!(PgLogLevel::ERROR, PgSqlErrorCode::ERRCODE_INTERNAL_ERROR, "oh noes!"); // abort the transaction
ereport!(PgLogLevel::LOG, PgSqlErrorCode::ERRCODE_SUCCESSFUL_COMPLETION, "this is just a message"); // log output only