message: Changes for DISTINCT tests now that ORDER BY on non-included columns is supported
diff: @@ -50,8 +50,22 @@ TEST_CASE("Test DISTINCT and ORDER BY", "[distinct]") {
  REQUIRE(CHECK_COLUMN(result, 0, {0, 1}));
  // controversial: Postgres fails here with the error "with SELECT DISTINCT columns from ORDER BY must appear in the
  - // SELECT clause" but SQLite succeeds for now we fail because it gives unintuitive results
  - REQUIRE_FAIL(con.Query("SELECT DISTINCT i%2 FROM integers ORDER BY i"));
  + // SELECT clause" but SQLite succeeds
  + // we also succeed here, even though it can give unintuitive results
  + // this is transformed into SELECT DISTINCT(1) i % 2, i
  + result = con.Query("SELECT DISTINCT i % 2 FROM integers WHERE i<3 ORDER BY i");
  + REQUIRE(CHECK_COLUMN(result, 0, {1, 0}));
  + result = con.Query("SELECT DISTINCT ON (1) i % 2, i FROM integers WHERE i<3 ORDER BY i");
  + REQUIRE(CHECK_COLUMN(result, 0, {1, 0}));
  + REQUIRE(CHECK_COLUMN(result, 1, {1, 2}));
  +
  + // binding of DISTINCT with column names
  + result = con.Query("SELECT DISTINCT integers.i FROM integers ORDER BY i DESC");
  + REQUIRE(CHECK_COLUMN(result, 0, {3, 2, 1}));
  + result = con.Query("SELECT DISTINCT i FROM integers ORDER BY integers.i DESC");
  + REQUIRE(CHECK_COLUMN(result, 0, {3, 2, 1}));
  + result = con.Query("SELECT DISTINCT integers.i FROM integers ORDER BY integers.i DESC");
  + REQUIRE(CHECK_COLUMN(result, 0, {3, 2, 1}));
  }
  TEST_CASE("Test DISTINCT ON", "[distinct]") {
  @@ -114,6 +128,28 @@ TEST_CASE("Test DISTINCT ON", "[distinct]") {
  REQUIRE(CHECK_COLUMN(result, 0, {4}));
  REQUIRE(CHECK_COLUMN(result, 1, {5}));
  + // order by a column that does not exist in the SELECT clause
  + result = con.Query("SELECT DISTINCT ON (i) i, j FROM integers ORDER BY k");
  + REQUIRE(CHECK_COLUMN(result, 0, {2, 4}));
  + REQUIRE(CHECK_COLUMN(result, 1, {3, 5}));
  + // equivalent to this, but without projecting the k
  + result = con.Query("SELECT DISTINCT ON (i) i, j, k FROM integers ORDER BY k");
  + REQUIRE(CHECK_COLUMN(result, 0, {2, 4}));
  + REQUIRE(CHECK_COLUMN(result, 1, {3, 5}));
  + REQUIRE(CHECK_COLUMN(result, 2, {5, 6}));
  +
  + // binding of DISTINCT ON with different column names
  + result = con.Query("SELECT DISTINCT ON (integers.i) i, j FROM integers ORDER BY 1, 2");
  + REQUIRE(CHECK_COLUMN(result, 0, {2, 4}));
  + REQUIRE(CHECK_COLUMN(result, 1, {3, 5}));
  + result = con.Query("SELECT DISTINCT ON (i) integers.i, integers.j FROM integers ORDER BY 1, 2");
  + REQUIRE(CHECK_COLUMN(result, 0, {2, 4}));
  + REQUIRE(CHECK_COLUMN(result, 1, {3, 5}));
  + result = con.Query("SELECT DISTINCT ON (integers.i) integers.i, integers.j FROM integers ORDER BY i, j");
  + REQUIRE(CHECK_COLUMN(result, 0, {2, 4}));
  + REQUIRE(CHECK_COLUMN(result, 1, {3, 5}));
  +
  +
  + // out of bounds
  REQUIRE_FAIL(con.Query("SELECT DISTINCT ON (2) i FROM integers"));
  - REQUIRE_FAIL(con.Query("SELECT DISTINCT ON (i) i, j FROM integers ORDER BY k"));
  }
  