Skip to content

Commit 006a559

Browse files
committed
PostgreSQL: Split the N string span in DO statement
Share the token span between the nchar language name and the code block it produces, so get_source returns N and the literal separately. Cover the split in the DO span test.
1 parent b4518cf commit 006a559

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

‎src/ast/spans.rs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3618,5 +3618,14 @@ SETTINGS update_parallel_mode = 'auto'"#;
36183618
let test = SpanTest::new(dialect, sql);
36193619
let r = Parser::parse_sql(dialect, sql).unwrap();
36203620
assert_eq!(test.get_source(r[0].span()), "plpgsql $$BEGIN NULL; END$$");
3621+
3622+
let sql = "DO LANGUAGE N'BEGIN NULL; END'";
3623+
let test = SpanTest::new(dialect, sql);
3624+
let options = match Parser::parse_sql(dialect, sql).unwrap().remove(0) {
3625+
Statement::Do(DoStatement { options }) => options,
3626+
stmt => panic!("expected DO, got {stmt:?}"),
3627+
};
3628+
assert_eq!(test.get_source(options[0].span()), "N");
3629+
assert_eq!(test.get_source(options[1].span()), "'BEGIN NULL; END'");
36213630
}
36223631
}

‎src/parser/mod.rs‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,8 +1569,11 @@ impl<'a> Parser<'a> {
15691569
token: Token::NationalStringLiteral(code),
15701570
span,
15711571
} => {
1572-
options.push(DoOption::Language(Ident::with_span(span, "nchar")));
1573-
DoOption::Code(Value::SingleQuotedString(code).with_span(span))
1572+
let quote = Location::new(span.start.line, span.start.column + 1);
1573+
let language = Ident::with_span(Span::new(span.start, quote), "nchar");
1574+
options.push(DoOption::Language(language));
1575+
let code = Value::SingleQuotedString(code);
1576+
DoOption::Code(code.with_span(Span::new(quote, span.end)))
15741577
}
15751578
_ => {
15761579
self.prev_token();

0 commit comments

Comments
 (0)