pub struct ViewDef {
pub name: String,
pub query: String,
pub materialized: bool,
pub security_invoker: bool,
}Expand description
A SQL view definition.
Fields§
§name: StringView name.
query: StringUnderlying SQL query.
materialized: boolWhether this is a MATERIALIZED VIEW.
security_invoker: boolWITH (security_invoker = true) — evaluate the base tables with the
CALLER’s privileges instead of the view owner’s.
Without it Postgres checks the base tables as the view OWNER, so any row-level security on them is bypassed: a tenant selecting through the view sees every tenant’s rows. Set this on any view over an RLS-protected table. Leave it off only for views that are deliberately owner-rights (a public projection that must be readable with no tenant context) — and say so in a comment, because the default is the unsafe direction. Requires PostgreSQL 15+; ignored on MATERIALIZED views, which Postgres does not support it for.
Implementations§
Source§impl ViewDef
impl ViewDef
Sourcepub fn new(name: impl Into<String>, query: impl Into<String>) -> Self
pub fn new(name: impl Into<String>, query: impl Into<String>) -> Self
Create a standard (non-materialized) view.
Sourcepub fn materialized(self) -> Self
pub fn materialized(self) -> Self
Mark as MATERIALIZED VIEW.
Sourcepub fn security_invoker(self) -> Self
pub fn security_invoker(self) -> Self
Evaluate base tables with the caller’s privileges so their RLS applies.