xitep commented on code in PR #2214:
URL:
https://github.com/apache/datafusion-sqlparser-rs/pull/2214#discussion_r2840880696
##########
tests/sqlparser_oracle.rs:
##########
@@ -421,3 +424,107 @@ fn test_connect_by() {
ORDER BY \"Employee\", \"Manager\", \"Pathlen\", \"Path\"",
);
}
+
+#[test]
+fn test_insert_with_table_alias() {
+ let oracle_dialect = oracle();
+
+ fn verify_table_name_with_alias(stmt: &Statement, exp_table_name: &str,
exp_table_alias: &str) {
+ assert!(matches!(stmt,
+ Statement::Insert(Insert {
+ table: TableObject::TableName(table_name),
+ table_alias: Some(TableAliasWithoutColumns {
+ explicit: false,
+ alias: Ident {
+ value: table_alias,
+ quote_style: None,
+ span: _
+ }
+ }),
+ ..
+ })
+ if table_alias == exp_table_alias
+ && table_name == &ObjectName::from(vec![Ident {
+ value: exp_table_name.into(),
+ quote_style: None,
+ span: Span::empty(),
+ }])
+ ));
+ }
+
+ let stmt = oracle_dialect.verified_stmt(
+ "INSERT INTO foo_t t \
+ SELECT 1, 2, 3 FROM dual",
+ );
+ verify_table_name_with_alias(&stmt, "foo_t", "t");
+
+ let stmt = oracle_dialect.verified_stmt(
+ "INSERT INTO foo_t asdf (a, b, c) \
+ SELECT 1, 2, 3 FROM dual",
+ );
+ verify_table_name_with_alias(&stmt, "foo_t", "asdf");
+
+ let stmt = oracle_dialect.verified_stmt(
+ "INSERT INTO foo_t t (a, b, c) \
+ VALUES (1, 2, 3)",
+ );
+ verify_table_name_with_alias(&stmt, "foo_t", "t");
+
+ let stmt = oracle_dialect.verified_stmt(
+ "INSERT INTO foo_t t \
+ VALUES (1, 2, 3)",
+ );
+ verify_table_name_with_alias(&stmt, "foo_t", "t");
+}
+
+#[test]
+fn test_insert_without_alias() {
+ let oracle_dialect = oracle();
+
+ // check DEFAULT
+ let sql = "INSERT INTO t default SELECT 'a' FROM dual";
+ assert_eq!(
+ oracle_dialect.parse_sql_statements(sql),
+ Err(ParserError::ParserError(
+ "Expected: SELECT, VALUES, or a subquery in the query body, found:
default".into()
+ ))
+ );
+
+ // check SELECT
+ let sql = "INSERT INTO t SELECT 'a' FROM dual";
+ let stmt = oracle_dialect.verified_stmt(sql);
+ assert!(matches!(
+ &stmt,
+ Statement::Insert(Insert {
+ table_alias: None,
+ source: Some(source),
+ ..
+ })
+ if matches!(&**source, Query { body, .. } if matches!(&**body,
SetExpr::Select(_)))));
+
+ // check WITH
+ let sql = "INSERT INTO dual WITH w AS (SELECT 1 AS y FROM dual) SELECT y
FROM w";
+ let stmt = oracle_dialect.verified_stmt(sql);
+ assert!(matches!(
+ &stmt,
+ Statement::Insert(Insert {
+ table_alias: None,
+ source: Some(source),
+ ..
+ })
+ if matches!(&**source, Query { body, .. } if matches!(&**body,
SetExpr::Select(_)))));
+
+ // check VALUES
+ let sql = "INSERT INTO t VALUES (1)";
+ let stmt = oracle_dialect.verified_stmt(sql);
+ dbg!(&stmt);
Review Comment:
uf! (i'm sorry.)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]