no-mistakes-postgres-sql 0.109.130

PostgreSQL SQL parsing, statement facts, and identifier extraction for no-mistakes
Documentation
use sqlparser::keywords::Keyword;
use sqlparser::tokenizer::Word;

/// Unquoted PostgreSQL reserved keywords. They are not column names.
/// Non-reserved keywords such as `KEY` stay eligible.
const RESERVED_COLUMN_NAME: &[Keyword] = &[
    Keyword::ALL,
    Keyword::ANALYZE,
    Keyword::AND,
    Keyword::ANY,
    Keyword::ARRAY,
    Keyword::AS,
    Keyword::ASC,
    Keyword::ASYMMETRIC,
    Keyword::AUTHORIZATION,
    Keyword::BINARY,
    Keyword::BOTH,
    Keyword::CASE,
    Keyword::CAST,
    Keyword::CHECK,
    Keyword::COLLATE,
    Keyword::COLLATION,
    Keyword::COLUMN,
    Keyword::CONCURRENTLY,
    Keyword::CONSTRAINT,
    Keyword::CREATE,
    Keyword::CROSS,
    Keyword::CURRENT_CATALOG,
    Keyword::CURRENT_DATE,
    Keyword::CURRENT_ROLE,
    Keyword::CURRENT_SCHEMA,
    Keyword::CURRENT_TIME,
    Keyword::CURRENT_TIMESTAMP,
    Keyword::CURRENT_USER,
    Keyword::DEFAULT,
    Keyword::DEFERRABLE,
    Keyword::DESC,
    Keyword::DISTINCT,
    Keyword::DO,
    Keyword::ELSE,
    Keyword::END,
    Keyword::EXCEPT,
    Keyword::FALSE,
    Keyword::FETCH,
    Keyword::FOR,
    Keyword::FOREIGN,
    Keyword::FREEZE,
    Keyword::FROM,
    Keyword::FULL,
    Keyword::GRANT,
    Keyword::GROUP,
    Keyword::HAVING,
    Keyword::ILIKE,
    Keyword::IN,
    Keyword::INITIALLY,
    Keyword::INNER,
    Keyword::INTERSECT,
    Keyword::INTO,
    Keyword::IS,
    Keyword::JOIN,
    Keyword::LATERAL,
    Keyword::LEADING,
    Keyword::LEFT,
    Keyword::LIKE,
    Keyword::LIMIT,
    Keyword::LOCALTIME,
    Keyword::LOCALTIMESTAMP,
    Keyword::NATURAL,
    Keyword::NOT,
    Keyword::NOTNULL,
    Keyword::NULL,
    Keyword::OFFSET,
    Keyword::ON,
    Keyword::ONLY,
    Keyword::OR,
    Keyword::ORDER,
    Keyword::OUTER,
    Keyword::OVERLAPS,
    Keyword::PLACING,
    Keyword::PRIMARY,
    Keyword::REFERENCES,
    Keyword::RETURNING,
    Keyword::RIGHT,
    Keyword::SELECT,
    Keyword::SESSION_USER,
    Keyword::SIMILAR,
    Keyword::SOME,
    Keyword::SYMMETRIC,
    Keyword::SYSTEM_USER,
    Keyword::TABLE,
    Keyword::TABLESAMPLE,
    Keyword::THEN,
    Keyword::TO,
    Keyword::TRAILING,
    Keyword::TRUE,
    Keyword::UNION,
    Keyword::UNIQUE,
    Keyword::USER,
    Keyword::USING,
    Keyword::VARIADIC,
    Keyword::VERBOSE,
    Keyword::WHEN,
    Keyword::WHERE,
    Keyword::WINDOW,
    Keyword::WITH,
];

pub(super) fn is_column_word(word: &Word) -> bool {
    if word.quote_style.is_some() {
        return true;
    }
    if word.value.eq_ignore_ascii_case("analyse") || word.value.eq_ignore_ascii_case("isnull") {
        return false;
    }
    !RESERVED_COLUMN_NAME.contains(&word.keyword)
}