 
 (deftest dsl-common-table-expressions
   (testing "Common table expressions"
-    (let [cte1 (-> (dsl/name :t1)
-                   (dsl/with-fields :f1 :f2)
-                   (dsl/as-table (dsl/select (dsl/val 1) (dsl/val "a"))))
-          cte2 (-> (dsl/name :t2)
-                   (dsl/with-fields :f1 :f2)
-                   (dsl/as-table (dsl/select (dsl/val 2) (dsl/val "b"))))
-          q1   (-> (dsl/with cte1 cte2)
-                   (dsl/select (dsl/field "t1.f2"))
-                   (dsl/from :t1 :t2))
+    (let [
+          ;; cte1 (-> (dsl/name :t1)
+          ;;          (dsl/with-fields :f1 :f2)
+          ;;          (dsl/to-table (dsl/select (dsl/val 1) (dsl/val "a"))))
+          ;; cte2 (-> (dsl/name :t2)
+          ;;          (dsl/with-fields :f1 :f2)
+          ;;          (dsl/to-table (dsl/select (dsl/val 2) (dsl/val "b"))))
+          ;; q1   (-> (dsl/with cte1 cte2)
+          ;;          (dsl/select (dsl/field "t1.f2"))
+          ;;          (dsl/from :t1 :t2))
 
           ;; Same as previous code but less verbose.
           q    (-> (dsl/with
                     (-> (dsl/name :t1)
                         (dsl/with-fields :f1 :f2)
-                        (dsl/as-table (dsl/select (dsl/val 1) (dsl/val "a"))))
+                        (dsl/to-table (dsl/select (dsl/val 1) (dsl/val "a"))))
                     (-> (dsl/name :t2)
                         (dsl/with-fields :f1 :f2)
-                        (dsl/as-table (dsl/select (dsl/val 2) (dsl/val "b")))))
+                        (dsl/to-table (dsl/select (dsl/val 2) (dsl/val "b")))))
                    (dsl/select (dsl/field "t1.f2"))
                    (dsl/from :t1 :t2))
           sql  (fmt/get-sql q {:type :inlined :dialect :pgsql})

      (is (= bv [2]))))

  (testing "Select clause with field as condition and alias"
    (let [q (-> (dsl/select ["foo > 5" "bar"])
                (dsl/from "baz"))]
      (is (= (fmt/get-sql q)
             "select foo > 5 \"bar\" from baz"))))

  (testing "Select clause with count(*) expresion"
    (let [q (-> (dsl/select ["count(*)" "count"])
                (dsl/from "baz"))]
      (is (= (fmt/get-sql q)
             "select count(*) \"count\" from baz"))))

  (testing "Select with two tables in from clause"
    (let [q (-> (dsl/select-one)
                (dsl/from
                 (dsl/table "table1" {:alias "foo"})
                 (dsl/table "table2" {:alias "bar"})))]
      (is (= (fmt/get-sql q)
             "select 1 \"one\" from table1 \"foo\", table2 \"bar\""))))

  (testing "Select with two tables in from clause 2"
    (let [q (-> (dsl/select-one)
                (dsl/from ["table1" "foo"]
                          ["table2" "bar"]))]
      (is (= (fmt/get-sql q)
             "select 1 \"one\" from table1 \"foo\", table2 \"bar\""))))

  (testing "Select clause with join"
    (let [q (-> (dsl/select-one)
                (dsl/from (dsl/table "book"))
                (dsl/join "author")
                (dsl/on "book.authorid = book.id"))]
      (is (= (fmt/get-sql q)

    (let [sq (-> (dsl/select (dsl/field "count(*)"))
                 (dsl/from :book)
                 (dsl/where "book.authorid = author.id"))
          q  (-> (dsl/select :fullname, (dsl/field sq "books"))
                 (dsl/from :author))]
      (is (= (fmt/get-sql q)
             "select fullname, (select count(*) from book where (book.authorid = author.id)) \"books\" from author"))))
