1#include "catch.hpp"
2#include "test_helpers.hpp"
3
4using namespace duckdb;
5using namespace std;
6
7TEST_CASE("Test scalar queries", "[scalarquery]") {
8 unique_ptr<QueryResult> result;
9 DuckDB db(nullptr);
10 Connection con(db);
11 con.EnableQueryVerification();
12
13 result = con.Query("SELECT 42");
14 REQUIRE(CHECK_COLUMN(result, 0, {42}));
15
16 result = con.Query("SELECT 42 + 1");
17 REQUIRE(CHECK_COLUMN(result, 0, {43}));
18
19 result = con.Query("SELECT 2 * (42 + 1), 35 - 2");
20 REQUIRE(CHECK_COLUMN(result, 0, {86}));
21 REQUIRE(CHECK_COLUMN(result, 1, {33}));
22
23 result = con.Query("SELECT 'hello'");
24 REQUIRE(CHECK_COLUMN(result, 0, {"hello"}));
25
26 result = con.Query("SELECT cast('3' AS INTEGER)");
27 REQUIRE(CHECK_COLUMN(result, 0, {3}));
28
29 result = con.Query("SELECT cast(3 AS VARCHAR)");
30 REQUIRE(CHECK_COLUMN(result, 0, {"3"}));
31
32 result = con.Query("SELECT CASE WHEN 43 > 33 THEN 43 ELSE 33 END;");
33 REQUIRE(CHECK_COLUMN(result, 0, {43}));
34
35 // cannot reference columns like this
36 REQUIRE_FAIL(con.Query("SELECT 1 AS a, a * 2"));
37 // query without selection list
38 REQUIRE_FAIL(con.Query("SELECT"));
39 REQUIRE_FAIL(con.Query("SELECT FROM (SELECT 42) v1"));
40}
41
42TEST_CASE("Test scalar queries from SQLLogicTests", "[scalarquery]") {
43 unique_ptr<QueryResult> result;
44 DuckDB db(nullptr);
45 Connection con(db);
46 con.EnableQueryVerification();
47
48 result = con.Query("SELECT + CASE WHEN NOT + 84 NOT BETWEEN - 78 + 98 * 51 AND - ( ( - 28 ) ) * COUNT ( * ) + + - "
49 "65 THEN NULL ELSE 16 / + 34 + + - 98 END / + 70 - ( - - CASE - COALESCE ( + 73, + - 66 * - 89 "
50 "* - 72 ) WHEN COUNT ( * ) / + 4 * CAST ( - - 18 AS INTEGER ) + + + COUNT ( * ) - - 88 THEN "
51 "NULL WHEN 92 THEN NULL ELSE COUNT ( * ) END ) AS col0");
52 REQUIRE(CHECK_COLUMN(result, 0, {-2}));
53}
54