diff --git a/pegjs/snowflake.pegjs b/pegjs/snowflake.pegjs index 6a344e91..911e042a 100644 --- a/pegjs/snowflake.pegjs +++ b/pegjs/snowflake.pegjs @@ -409,7 +409,7 @@ with_view_options create_view_stmt = a:KW_CREATE __ or:(KW_OR __ KW_REPLACE)? __ tp:(KW_TEMP / KW_TEMPORARY)? __ r:KW_RECURSIVE? __ KW_VIEW __ v:table_name __ c:(LPAREN __ column_list __ RPAREN)? __ wo:(KW_WITH __ LPAREN __ with_view_options __ RPAREN)? __ - KW_AS __ s:select_stmt_nake __ w:view_with? { + KW_AS __ s:select_stmt __ w:view_with? { /* export type create_view_stmt = { type: 'create', diff --git a/src/create.js b/src/create.js index 1e53c5d7..75b6e433 100644 --- a/src/create.js +++ b/src/create.js @@ -230,8 +230,8 @@ function createViewToSQL(stmt) { recursive, replace, select, sql_security: sqlSecurity, temporary, type, view, with: withClause, with_options: withOptions, } = stmt - const { db, view: name } = view - const viewName = [identifierToSql(db), identifierToSql(name)].filter(hasVal).join('.') + const { db, schema, view: name } = view + const viewName = [identifierToSql(db), identifierToSql(schema), identifierToSql(name)].filter(hasVal).join('.') const sql = [ toUpper(type), toUpper(replace), diff --git a/test/snowflake.spec.js b/test/snowflake.spec.js index 58e075d3..2659c697 100644 --- a/test/snowflake.spec.js +++ b/test/snowflake.spec.js @@ -390,6 +390,17 @@ describe('snowflake', () => { 'SELECT * EXCLUDE("user_id", "daily_iap", "iap_7d", "iap_30d", "purchases_cnt"), COUNT(DISTINCT "user_id") AS "DAU" FROM "tableName"' ] }, + { + title: 'create or replace view', + sql: [ + `create or replace view JACEK_DB.PUBLIC.VALIDATION_DATA_VIEW( + ID, + DATA, + LOLZ + ) as (SELECT *, DATA AS LOLZ FROM VALIDATION_DATA);`, + 'CREATE OR REPLACE VIEW "JACEK_DB"."PUBLIC"."VALIDATION_DATA_VIEW" ("ID", "DATA", "LOLZ") AS (SELECT *, "DATA" AS "LOLZ" FROM "VALIDATION_DATA")' + ] + }, ] SQL_LIST.forEach(sqlInfo => { const { title, sql } = sqlInfo