Skip to content
Open
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
12 changes: 8 additions & 4 deletions src/dialect/snowflake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1602,10 +1602,14 @@ fn parse_select_item_for_data_load(
}
}

// A trailing `::` means this is a cast expression (e.g.
// `$1:"col"::NUMBER(38,0)`), not a stage-load-select-item.
if matches!(parser.peek_token_ref().token, Token::DoubleColon) {
return parser.expected("stage load select item", parser.peek_token());
// More complex paths and casts must fall back to the standard expression
// parser so it can preserve the complete JsonAccess / Cast expression.
if matches!(
parser.peek_token_ref().token,
Token::Colon | Token::Period | Token::LBracket | Token::DoubleColon
) {
let token = parser.next_token();
return parser.expected("end of simple staged field", token);
}

// as
Expand Down
5 changes: 5 additions & 0 deletions tests/sqlparser_snowflake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2596,6 +2596,11 @@ fn test_copy_into_with_cast_transformation() {
"COPY INTO my_company.emp_basic (a, b) FROM ",
r#"(SELECT t.$1:plain AS plain, $1:"B"::TEXT FROM @stg AS t)"#,
),
// https://docs.snowflake.com/en/user-guide/tutorials/script-data-load-transform-parquet
concat!(
"COPY INTO my_company.emp_basic (a, b) FROM ",
"(SELECT $1:continent::VARCHAR, $1:country:name::VARCHAR FROM @stg)",
),
];
for sql in variants {
snowflake().verified_stmt(sql);
Expand Down
Loading