use pgrx::prelude::*;
#[pg_extern]
#[allow(clippy::needless_pass_by_value)] fn pg_tviews_convert_table(table_name: String, command_tag: default!(Option<String>, "NULL")) {
if matches!(
command_tag.as_deref(),
Some("CREATE TABLE AS" | "SELECT INTO")
) {
pgrx::pg_sys::panic::ErrorReport::new(
PgSqlErrorCode::ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE,
format!(
"pg_tviews: cannot convert '{table_name}' to a TVIEW: the statement was \
not intercepted"
),
function_name!(),
)
.set_detail("pg_tviews is not active in this session's ProcessUtility hook")
.set_hint(
"Add pg_tviews to shared_preload_libraries in postgresql.conf and restart \
PostgreSQL, or create the TVIEW with tviews.pg_tviews_create_or_replace().",
)
.report(PgLogLevel::ERROR);
}
}