Macro pgx::PANIC

source · []
macro_rules! PANIC {
    ($($arg:tt)*) => { ... };
}
Expand description

Log to Postgres’ panic log level. This will cause the entire Postgres cluster to crash.

This macro accepts arguments like the println and format macros. See fmt for information about options.

Given some function:

use pgx::*;

#[pg_extern]
fn sum_array(input: Array<i32>) -> i64 {
    let mut sum = 0 as i64;

    for i in input {
        pgx::PANIC!("i={index:?}, sum={}", sum, index = i);
        sum += i.unwrap_or(-1) as i64;
    }

    sum
}

When run inside PostgreSQL would output:

arrays=# SELECT arrays.sum_array('{1,2,3}');
PANIC:  i=Some(1), sum=0
server closed the connection unexpectedly
        This probably means the server terminated abnormally
        before or while processing the request.
The connection to the server was lost. Attempting reset: Failed.