                     :field :timestamp}
        "facts" {:type :queryable-json
                 :queryable? true
-                :field (hcore/raw "(stable||volatile)")}
+                :field {:select [(h/row-to-json :facts_data)]
+                        :from [[{:select [[(hcore/raw "json_agg(json_build_object('name', t.name, 'value', t.value))")
+                                           :data]
+                                          [(hsql-hash-as-href "fs.certname" :factsets :facts)
+                                           :href]]
+                                 :from [[{:select [[:key :name] :value :certname]
+                                          :from [(hcore/raw "jsonb_each(fs.volatile || fs.stable)")]}
+                                         :t]]}
+                                :facts_data]]}}
        "certname" {:type :string
                    :queryable? true
-                   :field :factsets.certname}
+                   :field :fs.certname}
        "hash" {:type :string
                :queryable? true
-               :field (hsql-hash-as-str :factsets.hash)}
+               :field (hsql-hash-as-str :fs.hash)}
        "producer_timestamp" {:type :timestamp
                              :queryable? true
-                             :field :factsets.producer_timestamp}
+                             :field :fs.producer_timestamp}
        "producer" {:type :string
                    :queryable? true
                    :field :producers.name}

                      :queryable? true
                      :field :environments.environment}}

      :selection {:from [:factsets]
                  :left-join [:environments
                              [:= :factsets.environment_id :environments.id]
                              :producers
                              [:= :producers.id :factsets.producer_id]]}

      :relationships (merge certname-relations
                            {"environments" {:local-columns ["environment"]


               :relationships certname-relations

               :alias "package_inventory
               :subquery? false
               :source-table packages"}))

(def factsets-query
  "Query for the top level facts query"
