Skip to content

Commit f535f45

Browse files
Merge pull request #2034 from taozhi8833998/fix-create-view-snowflake
fix: create or replace view in snowflake
2 parents 6d4be38 + b775677 commit f535f45

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

pegjs/snowflake.pegjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ with_view_options
409409
create_view_stmt
410410
= a:KW_CREATE __ or:(KW_OR __ KW_REPLACE)? __ tp:(KW_TEMP / KW_TEMPORARY)? __ r:KW_RECURSIVE? __
411411
KW_VIEW __ v:table_name __ c:(LPAREN __ column_list __ RPAREN)? __ wo:(KW_WITH __ LPAREN __ with_view_options __ RPAREN)? __
412-
KW_AS __ s:select_stmt_nake __ w:view_with? {
412+
KW_AS __ s:select_stmt __ w:view_with? {
413413
/*
414414
export type create_view_stmt = {
415415
type: 'create',

src/create.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,8 @@ function createViewToSQL(stmt) {
230230
recursive, replace, select, sql_security: sqlSecurity,
231231
temporary, type, view, with: withClause, with_options: withOptions,
232232
} = stmt
233-
const { db, view: name } = view
234-
const viewName = [identifierToSql(db), identifierToSql(name)].filter(hasVal).join('.')
233+
const { db, schema, view: name } = view
234+
const viewName = [identifierToSql(db), identifierToSql(schema), identifierToSql(name)].filter(hasVal).join('.')
235235
const sql = [
236236
toUpper(type),
237237
toUpper(replace),

test/snowflake.spec.js

+11
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,17 @@ describe('snowflake', () => {
390390
'SELECT * EXCLUDE("user_id", "daily_iap", "iap_7d", "iap_30d", "purchases_cnt"), COUNT(DISTINCT "user_id") AS "DAU" FROM "tableName"'
391391
]
392392
},
393+
{
394+
title: 'create or replace view',
395+
sql: [
396+
`create or replace view JACEK_DB.PUBLIC.VALIDATION_DATA_VIEW(
397+
ID,
398+
DATA,
399+
LOLZ
400+
) as (SELECT *, DATA AS LOLZ FROM VALIDATION_DATA);`,
401+
'CREATE OR REPLACE VIEW "JACEK_DB"."PUBLIC"."VALIDATION_DATA_VIEW" ("ID", "DATA", "LOLZ") AS (SELECT *, "DATA" AS "LOLZ" FROM "VALIDATION_DATA")'
402+
]
403+
},
393404
]
394405
SQL_LIST.forEach(sqlInfo => {
395406
const { title, sql } = sqlInfo

0 commit comments

Comments
 (0)