no-mistakes-postgres-sql 0.109.131

PostgreSQL SQL parsing, statement facts, and identifier extraction for no-mistakes
Documentation
use super::References;
use crate::idents::{dot_field_names, ident_key, named_argument_labels};
use crate::statements::keyed_lookups::{
    query::outputs::wildcard_owners::{function_wildcards, local_relation_key},
    table::column_reference,
};
use sqlparser::ast::Expr;

impl References<'_> {
    pub(super) fn enter_expr(&mut self, expr: &Expr) {
        self.windows.enter(expr, &mut self.candidates);
        self.outputs.enter(expr, &mut self.candidates);
        self.nested.enter_expression(expr);
        match expr {
            Expr::Identifier(name)
                if !self.outputs.labels.contains(&std::ptr::from_ref(expr))
                    && !self.ignored_names.remove(&std::ptr::from_ref(expr)) =>
            {
                let name = ident_key(name);
                if !self.nested.contains_column(&name) {
                    self.bare(&name);
                }
            }
            Expr::CompoundIdentifier(parts) => {
                if let Some((name, qualifier)) = column_reference(parts) {
                    self.qualified(&qualifier, Some(&ident_key(name)));
                }
            }
            Expr::CompoundFieldAccess { access_chain, .. } => {
                self.ignored_names
                    .extend(dot_field_names(access_chain).map(std::ptr::from_ref));
            }
            Expr::QualifiedWildcard(name, _) => self.qualified(&local_relation_key(name), None),
            Expr::Function(function) => {
                self.ignored_names
                    .extend(named_argument_labels(function).map(std::ptr::from_ref));
                self.read_named_window(function);
                let nested = self.ctes.len() > self.outputs.projection_depth.max(1);
                self.outputs
                    .include_row_function(function, &self.nested, nested);
                for name in function_wildcards(function) {
                    self.qualified(&local_relation_key(name), None);
                }
            }
            _ => {}
        }
    }

    pub(super) fn leave_expr(&mut self, expr: &Expr) {
        self.nested.leave_expression(expr);
        self.outputs.leave(expr, &mut self.candidates);
        self.windows.leave(expr, &mut self.candidates);
    }
}