Skip to content

Commit fcda7d7

Browse files
committed
Generalize test for all dialects
1 parent 1dee2d5 commit fcda7d7

2 files changed

Lines changed: 34 additions & 34 deletions

File tree

tests/sqlparser_common.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13525,6 +13525,40 @@ fn insert_into_with_parentheses() {
1352513525
dialects.verified_stmt(r#"INSERT INTO t1 ("select", name) (SELECT t2.name FROM t2)"#);
1352613526
}
1352713527

13528+
#[test]
13529+
fn test_insert_with_query_table() {
13530+
let dialects = all_dialects_where(|d| d.supports_insert_table_query());
13531+
13532+
// a simple query (block); i.e. SELECT ...
13533+
let sql = "INSERT INTO (SELECT employee_id, last_name FROM employees) VALUES (207, 'Gregory')";
13534+
dialects.verified_stmt(sql);
13535+
13536+
// a full blown query; i.e. `WITH ... SELECT .. ORDER BY ...`
13537+
let sql = "INSERT INTO \
13538+
(WITH cte AS (SELECT 1 AS id, 2 AS val FROM dual) SELECT foo_t.id, foo_t.val FROM foo_t \
13539+
WHERE EXISTS (SELECT 1 FROM cte WHERE cte.id = foo_t.id) ORDER BY 1, 2) \
13540+
(id, val) \
13541+
VALUES (1000, 10101)";
13542+
dialects.verified_stmt(sql);
13543+
13544+
// an alias to the insert target query table
13545+
let sql = "INSERT INTO \
13546+
(WITH cte AS (SELECT 1 AS id, 2 AS val FROM dual) SELECT foo_t.id, foo_t.val FROM foo_t \
13547+
WHERE EXISTS (SELECT 1 FROM cte WHERE cte.id = foo_t.id)) abc \
13548+
(id, val) \
13549+
VALUES (1000, 10101)";
13550+
dialects.verified_stmt(sql);
13551+
13552+
// a query table target and a query source
13553+
let sql = "INSERT INTO (SELECT foo_t.id, foo_t.val FROM foo_t) SELECT 10, 20 FROM dual";
13554+
dialects.verified_stmt(sql);
13555+
13556+
// a query table target and a query source, with explicit columns
13557+
let sql =
13558+
"INSERT INTO (SELECT foo_t.id, foo_t.val FROM foo_t) (id, val) SELECT 10, 20 FROM dual";
13559+
dialects.verified_stmt(sql);
13560+
}
13561+
1352813562
#[test]
1352913563
fn parse_odbc_scalar_function() {
1353013564
let select = verified_only_select("SELECT {fn my_func(1, 2)}");

tests/sqlparser_oracle.rs

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -542,37 +542,3 @@ fn test_insert_without_alias() {
542542
if matches!(&*source, Query { body, .. } if matches!(&**body, SetExpr::Values(_)))
543543
));
544544
}
545-
546-
#[test]
547-
fn test_insert_with_query_table() {
548-
let oracle_dialect = oracle();
549-
550-
// a simple query (block); i.e. SELECT ...
551-
let sql = "INSERT INTO (SELECT employee_id, last_name FROM employees) VALUES (207, 'Gregory')";
552-
oracle_dialect.verified_stmt(sql);
553-
554-
// a full blown query; i.e. `WITH ... SELECT .. ORDER BY ...`
555-
let sql = "INSERT INTO \
556-
(WITH cte AS (SELECT 1 AS id, 2 AS val FROM dual) SELECT foo_t.id, foo_t.val FROM foo_t \
557-
WHERE EXISTS (SELECT 1 FROM cte WHERE cte.id = foo_t.id) ORDER BY 1, 2) \
558-
(id, val) \
559-
VALUES (1000, 10101)";
560-
oracle_dialect.verified_stmt(sql);
561-
562-
// an alias to the insert target query table
563-
let sql = "INSERT INTO \
564-
(WITH cte AS (SELECT 1 AS id, 2 AS val FROM dual) SELECT foo_t.id, foo_t.val FROM foo_t \
565-
WHERE EXISTS (SELECT 1 FROM cte WHERE cte.id = foo_t.id)) abc \
566-
(id, val) \
567-
VALUES (1000, 10101)";
568-
oracle_dialect.verified_stmt(sql);
569-
570-
// a query table target and a query source
571-
let sql = "INSERT INTO (SELECT foo_t.id, foo_t.val FROM foo_t) SELECT 10, 20 FROM dual";
572-
oracle_dialect.verified_stmt(sql);
573-
574-
// a query table target and a query source, with explicit columns
575-
let sql =
576-
"INSERT INTO (SELECT foo_t.id, foo_t.val FROM foo_t) (id, val) SELECT 10, 20 FROM dual";
577-
oracle_dialect.verified_stmt(sql);
578-
}

0 commit comments

Comments
 (0)