MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / quoteIdentifier

Function quoteIdentifier

console/src/api/materialize/index.ts:83–97  ·  view source on GitHub ↗
(identifier: string)

Source from the content-addressed store, hash-verified

81 * It is an error to call this function with a string that contains the zero code point.
82 */
83export function quoteIdentifier(identifier: string) {
84 // According to https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS,
85 // any string may be used as an identifier, except those that contain the zero code point.
86 //
87 // In order to support special characters, quoted identifiers must be used.
88 // Within a quoted identifier, the literal double-quote character must be escaped
89 // by writing it twice.
90 // For example, the identifier foo" is represented as "foo""" (including the quotes).
91
92 // Materialize never allows any identifiers to be used whose name contains the null byte,
93 // so this assert should never fire unless this function is called with arbitrary user input.
94 assert(identifier.search("\0") === -1);
95
96 return `"${identifier.replace(/"/g, '""')}"`;
97}
98
99/**
100 * Given an array of sql expressions, builds a string of WHERE + AND clauses.

Callers 4

ShellHeaderFunction · 0.90
index.test.tsFile · 0.90

Calls 2

assertFunction · 0.90
replaceMethod · 0.45

Tested by

no test coverage detected