Repository navigation
Expand file tree
/
Copy pathsql-writing.ts
More file actions
58 lines (57 loc) · 2.56 KB
/
Copy pathsql-writing.ts
File metadata and controls
58 lines (57 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import {
EXACT_DECIMAL_TYPE_NAMES,
FLOAT64_TYPE_NAMES,
identifierDoubleQuoted,
INSTANT_TYPE_NAMES,
literalDoubleAndBackslash,
NO_BARE_SPELLING,
NOTHING_STANDS_ALONE,
STANDARD_TYPE_VOCABULARY,
unquoteDoubleAndBackslash,
} from "@/lib/db/sql-writing/shared";
import { binaryStandardHex } from "@/lib/db/sql-writing/export-shared";
import { snowflakeLiteral, snowflakeVectorDeclaration } from "./typed-literals";
import type { SqlWritingSpec } from "@/lib/db/sql-writing/types";
/** How a generated statement spells a literal, a name and a bind for Snowflake. */
export const SNOWFLAKE_SQL_WRITING: SqlWritingSpec = {
// Snowflake reads both escapes in a single-quoted string constant: a doubled quote is one quote, and a backslash
// escapes the next character, so it is doubled first, as Databend's is.
escapeLiteral: literalDoubleAndBackslash,
unescapeLiteral: unquoteDoubleAndBackslash,
quoteIdentifier: identifierDoubleQuoted,
placeholder: null,
temporalLiteral: null,
inlineEdit: {
instantTypeNames: INSTANT_TYPE_NAMES,
exactDecimalTypeNames: EXACT_DECIMAL_TYPE_NAMES,
float64TypeNames: FLOAT64_TYPE_NAMES,
},
export: {
// Snowflake's float type is FLOAT and its byte type BINARY; it has no BLOB. Provisional until a replay on an account.
ddlTypes: {
text: "TEXT",
integer: "BIGINT",
numeric: "FLOAT",
boolean: "BOOLEAN",
timestamp: "TIMESTAMP",
binary: "BINARY",
},
// Not measured: no Snowflake account read a probe column back for this change, so every bare name is re-spelled
// portably until one does.
standsAlone: NOTHING_STANDS_ALONE,
bareSpelling: NO_BARE_SPELLING,
typeVocabulary: STANDARD_TYPE_VOCABULARY,
// Snowflake reads `X'0102deadbeef'` as a BINARY constant, the standard form; not yet measured on an account.
binaryLiteral: binaryStandardHex,
// Snowflake's trial setup (2026-10-12) created its FLOAT infinities with `'inf'::FLOAT` and `'-inf'::FLOAT`, and
// `'NaN'::FLOAT` is the same documented form.
nonFinite: { NaN: "'NaN'::FLOAT", Infinity: "'inf'::FLOAT", "-Infinity": "'-inf'::FLOAT" },
// Snowflake's `INSERT ... VALUES` refuses `PARSE_JSON`, which its semi-structured cells are written with
// (`typed-literals.ts`), so every Snowflake row takes the SELECT form. Provisional until a replay on an account
// confirms it.
insertForm: "select",
typedLiteral: snowflakeLiteral,
declareFromSample: (declared, sample) =>
declared.trim().toUpperCase() === "VECTOR" ? snowflakeVectorDeclaration(sample) : undefined,
},
};