no-mistakes-postgres-sql 0.109.128

PostgreSQL SQL parsing, statement facts, and identifier extraction for no-mistakes
Documentation
use crate::idents::ident_key;
use sqlparser::ast::ObjectName;

/// Common PostgreSQL builtins with scalar return cardinality. Unknown names stay opaque;
/// this is an explicit semantic inventory, not a naming convention or catalog fallback.
#[rustfmt::skip]
pub const SCALAR: &[&str] = &[
    "abs",
    "acos",
    "array_append",
    "array_cat",
    "array_length",
    "array_ndims",
    "array_position",
    "array_positions",
    "array_prepend",
    "array_remove",
    "array_replace",
    "array_to_string",
    "asin",
    "atan",
    "atan2",
    "btrim",
    "cardinality",
    "ceil",
    "ceiling",
    "char_length",
    "character_length",
    "clock_timestamp",
    "concat",
    "concat_ws",
    "cos",
    "date_part",
    "date_trunc",
    "decode",
    "encode",
    "exp",
    "floor",
    "format",
    "gen_random_uuid",
    "json_array_length",
    "json_build_array",
    "json_build_object",
    "json_extract_path",
    "json_extract_path_text",
    "json_typeof",
    "jsonb_array_length",
    "jsonb_build_array",
    "jsonb_build_object",
    "jsonb_extract_path",
    "jsonb_extract_path_text",
    "jsonb_typeof",
    "left",
    "length",
    "ln",
    "log",
    "lower",
    "lpad",
    "ltrim",
    "make_interval",
    "md5",
    "now",
    "octet_length",
    "pg_backend_pid",
    "pg_column_size",
    "pg_typeof",
    "power",
    "quote_ident",
    "quote_literal",
    "quote_nullable",
    "regexp_count",
    "regexp_instr",
    "regexp_match",
    "regexp_replace",
    "regexp_substr",
    "repeat",
    "replace",
    "reverse",
    "right",
    "round",
    "rpad",
    "rtrim",
    "sign",
    "sin",
    "split_part",
    "sqrt",
    "starts_with",
    "statement_timestamp",
    "string_to_array",
    "strpos",
    "substr",
    "substring",
    "tan",
    "to_char",
    "to_date",
    "to_json",
    "to_jsonb",
    "to_number",
    "to_timestamp",
    "transaction_timestamp",
    "translate",
    "trunc",
    "upper",
    "uuid_extract_timestamp",
    "uuid_extract_version",
];

/// SQL datetime keywords. PostgreSQL parses them as calls, and they are absent from pg_proc.
#[rustfmt::skip]
const DATETIME_KEYWORDS: &[&str] = &[
    "current_date",
    "current_time",
    "current_timestamp",
    "localtime",
    "localtimestamp",
];

/// Unquoted unqualified keyword. A quoted or schema-qualified spelling is an ordinary call.
pub(super) fn is_datetime_keyword(name: &ObjectName) -> bool {
    let [sqlparser::ast::ObjectNamePart::Identifier(ident)] = name.0.as_slice() else {
        return false;
    };
    ident.quote_style.is_none() && DATETIME_KEYWORDS.contains(&ident_key(ident).as_str())
}