     (let [per-dataset-collection
           (group-by #(select-keys % [:dataset :collection]) features)]
       (doseq [[{:keys [dataset collection]} collection-features] per-dataset-collection]
-        (let [sql (gs-delete-sql dataset collection)
+        (let [sql (gs-delete-sql dataset (visualization dataset collection))
               ids (map #(vector (:id %)) collection-features)]
           (j/execute! db (cons sql ids) :multi? true :transaction? false))))))
 

        (let [keyed (group-by feature-keys collection-features)]
          (doseq [[columns vals] keyed]
            (when (< 0 (count columns))
              (let [sql (gs-update-sql dataset collection (map name columns))
                    update-vals (map feature-to-update-record vals)]
                (j/execute! db (cons sql update-vals) :multi? true :transaction? false)))))
        ))

           (let [all-attributes (all-attributes-fn dataset collection)
                 records (map #(feature-to-sparse-record % (all-fields-constructor all-attributes)) grouped-features)
                 fields (concat [:_id :_geometry] (map (comp keyword pg/quoted) all-attributes))]
                          (apply (partial j/insert! c (str dataset "." (pg/quoted (visualization dataset collection))) fields) records)))))
      (catch java.sql.SQLException e (j/print-sql-exception-chain e))))
  )

