Skip to content

Commit ecd9e87

Browse files
Test XMLCONCAT parsing across dialects
1 parent 358a9fc commit ecd9e87

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

tests/sqlparser_common.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18779,3 +18779,20 @@ fn parse_non_pg_dialects_keep_xml_names_as_regular_identifiers() {
1877918779
let dialects = all_dialects_except(|d| d.supports_xml_expressions());
1878018780
dialects.verified_only_select("SELECT xml FROM t");
1878118781
}
18782+
18783+
#[test]
18784+
fn parse_non_pg_dialects_keep_xml_names_as_regular_functions() {
18785+
// On dialects that do NOT support XML expressions, `xmlconcat(...)`
18786+
// should parse as a plain function call, not as `Expr::XmlConcat`.
18787+
let dialects = all_dialects_except(|d| d.supports_xml_expressions());
18788+
for fn_name in ["xmlconcat"] {
18789+
let sql = format!("SELECT {fn_name}(1, 2)");
18790+
let select = dialects.verified_only_select(&sql);
18791+
match expr_from_projection(&select.projection[0]) {
18792+
Expr::Function(func) => {
18793+
assert_eq!(func.name.to_string(), fn_name);
18794+
}
18795+
other => panic!("Expected Expr::Function for {fn_name}, got: {other:?}"),
18796+
}
18797+
}
18798+
}

tests/sqlparser_postgres.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3750,6 +3750,31 @@ fn parse_on_commit() {
37503750
pg_and_generic().verified_stmt("CREATE TEMPORARY TABLE table (COL INT) ON COMMIT DROP");
37513751
}
37523752

3753+
#[test]
3754+
fn parse_xmlconcat_expression() {
3755+
// XMLCONCAT should parse as a dedicated Expr::XmlConcat variant on
3756+
// PostgreSQL and Generic, preserving argument order.
3757+
let sql = "SELECT XMLCONCAT('<a/>', '<b/>', '<c/>')";
3758+
let select = pg_and_generic().verified_only_select(sql);
3759+
match expr_from_projection(&select.projection[0]) {
3760+
Expr::XmlConcat(exprs) => {
3761+
assert_eq!(exprs.len(), 3);
3762+
let strings: Vec<String> = exprs
3763+
.iter()
3764+
.map(|e| match e {
3765+
Expr::Value(v) => match &v.value {
3766+
Value::SingleQuotedString(s) => s.clone(),
3767+
other => panic!("Expected SingleQuotedString, got: {other:?}"),
3768+
},
3769+
other => panic!("Expected Value, got: {other:?}"),
3770+
})
3771+
.collect();
3772+
assert_eq!(strings, vec!["<a/>", "<b/>", "<c/>"]);
3773+
}
3774+
other => panic!("Expected Expr::XmlConcat, got: {other:?}"),
3775+
}
3776+
}
3777+
37533778
#[test]
37543779
fn parse_xml_typed_string() {
37553780
// xml '...' should parse as a TypedString on PostgreSQL and Generic

0 commit comments

Comments
 (0)