| 1 | #include "catch.hpp" |
| 2 | #include "test_helpers.hpp" |
| 3 | |
| 4 | using namespace duckdb; |
| 5 | using namespace std; |
| 6 | |
| 7 | TEST_CASE("Create table from SELECT statement" , "[catalog]" ) { |
| 8 | unique_ptr<QueryResult> result; |
| 9 | DuckDB db(nullptr); |
| 10 | Connection con(db); |
| 11 | |
| 12 | REQUIRE_NO_FAIL(con.Query("CREATE TABLE integers(i INTEGER);" )); |
| 13 | REQUIRE_NO_FAIL(con.Query("INSERT INTO integers VALUES (3), (4), (5)" )); |
| 14 | |
| 15 | result = con.Query("SELECT * FROM integers" ); |
| 16 | REQUIRE(CHECK_COLUMN(result, 0, {3, 4, 5})); |
| 17 | |
| 18 | REQUIRE_NO_FAIL(con.Query("INSERT INTO integers SELECT i+3 FROM integers;" )); |
| 19 | |
| 20 | result = con.Query("SELECT * FROM integers" ); |
| 21 | REQUIRE(CHECK_COLUMN(result, 0, {3, 4, 5, 6, 7, 8})); |
| 22 | |
| 23 | REQUIRE_NO_FAIL(con.Query("CREATE TABLE integers2 AS SELECT i, i+2 AS j FROM integers;" )); |
| 24 | |
| 25 | result = con.Query("SELECT * FROM integers2 ORDER BY i" ); |
| 26 | REQUIRE(CHECK_COLUMN(result, 0, {3, 4, 5, 6, 7, 8})); |
| 27 | REQUIRE(CHECK_COLUMN(result, 1, {5, 6, 7, 8, 9, 10})); |
| 28 | |
| 29 | result = con.Query("SELECT i FROM integers2 ORDER BY i" ); |
| 30 | REQUIRE(CHECK_COLUMN(result, 0, {3, 4, 5, 6, 7, 8})); |
| 31 | |
| 32 | result = con.Query("SELECT j FROM integers2 ORDER BY i" ); |
| 33 | REQUIRE(CHECK_COLUMN(result, 0, {5, 6, 7, 8, 9, 10})); |
| 34 | } |
| 35 | |