Skip to content

Commit

Permalink
Merge pull request #2034 from taozhi8833998/fix-create-view-snowflake
Browse files Browse the repository at this point in the history
fix: create or replace view in snowflake
  • Loading branch information
taozhi8833998 authored Jul 31, 2024
2 parents 6d4be38 + b775677 commit f535f45
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pegjs/snowflake.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions src/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
11 changes: 11 additions & 0 deletions test/snowflake.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f535f45

Please sign in to comment.