Skip to content

Commit 797258f

Browse files
Merge pull request #2544 from taozhi8833998/fix-sqlify-bug
fix: multiple array index when sqlify back
2 parents 23b14b7 + 9d6eb3f commit 797258f

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/column.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ function columnToSQL(column, isDual) {
184184
return result.filter(hasVal).join(' ')
185185
}
186186
if (expr.parentheses && Reflect.has(expr, 'array_index') && expr.type !== 'cast') str = `(${str})`
187-
if (expr.array_index && expr.type !== 'column_ref') {
187+
if (expr.array_index && expr.type !== 'column_ref' && expr.type !== 'function') {
188188
str = `${str}${arrayIndexToSQL(expr.array_index)}`
189189
}
190190
return [str, asToSQL(column.as)].filter(hasVal).join(' ')

test/snowflake.spec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,13 @@ describe('snowflake', () => {
539539
'SELECT "my ""column"""'
540540
]
541541
},
542+
{
543+
title: 'array index',
544+
sql: [
545+
"SELECT split('12-34', '-')[0] FROM DUAL",
546+
"SELECT split('12-34', '-')[0] FROM DUAL"
547+
]
548+
},
542549
]
543550
SQL_LIST.forEach(sqlInfo => {
544551
const { title, sql } = sqlInfo

0 commit comments

Comments
 (0)