Closed bendlas closed 13 years ago
(ns gist
(:require [clojureql.core :as cql]))
(def schema-tables
(cql/select
(cql/table *db* :information_schema.tables)
(cql/where (= :table_schema "public"))))
(def table-columns
(cql/project
(cql/table server/*db* :information_schema.columns)
[:data_type]))
(def table-desc
(cql/join schema-tables table-columns :table_name))
@table-desc
;; throws (PG), since column :table_schema is ambigous
;; current workaround is to write the WHERE clause as (= :tables.table_schema "public")
Pasting here for ease of reading
Also including repl output (bendlas: please always add this to issue reports)
gist> table-desc
SELECT information_schema.tables.*,information_schema.columns.data_type FROM information_schema.tables JOIN information_schema.columns USING(table_name) WHERE (table_schema = public)
This commit should fix your problem https://github.com/LauJensen/clojureql/commit/bf9f5c2ed42dc62937ff8ea008cc7d1adb5a77e1
https://gist.github.com/772953
In this example two table defs that work fine by themselves, produce an ambigous column ref error when joined. This is because both have a column :table_schema and the first table has a WHERE clause on it.
When the join is flattened into a single SQL select, the column ref in the WHERE clause is not table-qualified, leading to the error.