Skip to content

quote_ident - actual C definition #238

Description

@pyramation

Our Code

private static readonly RESERVED_WORDS = new Set([
'all', 'analyse', 'analyze', 'and', 'any', 'array', 'as', 'asc', 'asymmetric', 'both',
'case', 'cast', 'check', 'collate', 'column', 'constraint', 'create', 'current_catalog',
'current_date', 'current_role', 'current_time', 'current_timestamp', 'current_user',
'default', 'deferrable', 'desc', 'distinct', 'do', 'else', 'end', 'except', 'false',
'fetch', 'for', 'foreign', 'from', 'grant', 'group', 'having', 'in', 'initially',
'intersect', 'into', 'lateral', 'leading', 'limit', 'localtime', 'localtimestamp',
'not', 'null', 'offset', 'on', 'only', 'or', 'order', 'placing', 'primary',
'references', 'returning', 'select', 'session_user', 'some', 'symmetric', 'table',
'then', 'to', 'trailing', 'true', 'union', 'unique', 'user', 'using', 'variadic',
'when', 'where', 'window', 'with'
]);
private static needsQuotes(value: string): boolean {
if (!value) return false;
const needsQuotesRegex = /[a-z]+[\W\w]*[A-Z]+|[A-Z]+[\W\w]*[a-z]+|\W/;
const isAllUppercase = /^[A-Z]+$/.test(value);
return needsQuotesRegex.test(value) ||
Deparser.RESERVED_WORDS.has(value.toLowerCase()) ||
isAllUppercase;
}

PG Source

https://github.com/postgres/postgres/blob/fab5cd3dd1323f9e66efeb676c4bb212ff340204/src/backend/utils/adt/ruleutils.c#L13055-L13137

https://github.com/postgres/postgres/blob/fab5cd3dd1323f9e66efeb676c4bb212ff340204/src/backend/utils/adt/ruleutils.c#L13139-L13156

doxygen

https://doxygen.postgresql.org/ruleutils_8c.html#a8c18b3ffb8863e7740b32ef5f4c05ddc
and keywords too

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions