Skip to content

fix: create or replace view in snowflake #2034

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 31, 2024
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
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