Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 27 additions & 12 deletions pegjs/snowflake.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,19 @@
function commonStrToLiteral(strOrLiteral) {
return typeof strOrLiteral === 'string' ? { type: 'same', value: strOrLiteral } : strOrLiteral
}

function getSurroundFromLiteralType(literal) {
switch (literal.type) {
case 'double_quote_string':
return '"'
case 'single_quote_string':
return "'"
case 'backticks_quote_string':
return '`'
default:
return ''
}
}

const cmpPrefixMap = {
'+': true,
Expand Down Expand Up @@ -2524,13 +2537,14 @@ join_op
/ (KW_INNER __)? KW_JOIN { /* => 'INNER JOIN' */ return 'INNER JOIN'; }

table_name
= dt:ident schema:(__ DOT __ ident) tail:(__ DOT __ ident) {
// => { db?: ident; schema?: ident, table: ident | '*'; }
const obj = { db: null, table: dt, ...getLocationObject(), };
= db:ident_without_kw_type schema:(__ DOT __ ident_without_kw_type) tail:(__ DOT __ ident_without_kw_type) {
const obj = { db: null, table: db.value };
if (tail !== null) {
obj.db = dt;
obj.schema = schema[3];
obj.table = tail[3];
obj.db = db.value;
obj.catalog = db.value;
obj.schema = schema[3].value;
obj.table = tail[3].value;
obj.surround = { table: getSurroundFromLiteralType(tail[3]), db: getSurroundFromLiteralType(db), schema: getSurroundFromLiteralType(schema[3]) };
}
return obj;
}
Expand All @@ -2542,21 +2556,22 @@ table_name
...getLocationObject(),
}
}
/ dt:ident tail:(__ DOT __ ident)? {
// => IGNORE
const obj = { db: null, table: dt, ...getLocationObject(), };
/ dt:ident_without_kw_type tail:(__ DOT __ ident_without_kw_type)? {
const obj = { db: null, table: dt.value, surround: { table: getSurroundFromLiteralType(dt) } };
if (tail !== null) {
obj.db = dt;
obj.table = tail[3];
obj.db = dt.value;
obj.table = tail[3].value;
obj.surround = { table: getSurroundFromLiteralType(tail[3]), db: getSurroundFromLiteralType(dt) };
}
return obj;
}
/ v:var_decl {
/ v:var_decl {
// => IGNORE
v.db = null;
v.table = v.name;
return v;
}


or_and_expr
= head:expr tail:(__ (KW_AND / KW_OR) __ expr)* {
Expand Down
2 changes: 1 addition & 1 deletion src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ function identifierToSql(ident, isDual, surround) {
if (isDual === true) return `'${ident}'`
if (!ident) return
if (ident === '*') return ident
if (surround) return `${surround}${ident}${surround}`
if (surround != null) return `${surround}${ident}${surround}`
const { database } = getParserOpt()
switch (database && database.toLowerCase()) {
case 'mysql':
Expand Down
Loading