diff --git a/modules/drivers/redshift/src/metabase/driver/redshift.clj b/modules/drivers/redshift/src/metabase/driver/redshift.clj index b8f2c6ae7b79ef884d111bdb614cc1f22cf5b36b..b9224530babf89f775726a6664c7fd6fe8615db1 100644 --- a/modules/drivers/redshift/src/metabase/driver/redshift.clj +++ b/modules/drivers/redshift/src/metabase/driver/redshift.clj @@ -49,38 +49,6 @@ [& args] (apply (get-method driver/describe-table :sql-jdbc) args)) -;; The Postgres JDBC .getImportedKeys method doesn't work for Redshift, and we're not allowed to access -;; information_schema.constraint_column_usage, so we'll have to use this custom query instead -;; -;; See also: [Related Postgres JDBC driver issue on GitHub](https://github.com/pgjdbc/pgjdbc/issues/79) -;; [How to access the equivalent of information_schema.constraint_column_usage in Redshift](https://forums.aws.amazon.com/thread.jspa?threadID=133514) -(def ^:private fk-query - "SELECT source_column.attname AS \"fk-column-name\", - dest_table.relname AS \"dest-table-name\", - dest_table_ns.nspname AS \"dest-table-schema\", - dest_column.attname AS \"dest-column-name\" - FROM pg_constraint c - JOIN pg_namespace n ON c.connamespace = n.oid - JOIN pg_class source_table ON c.conrelid = source_table.oid - JOIN pg_attribute source_column ON c.conrelid = source_column.attrelid - JOIN pg_class dest_table ON c.confrelid = dest_table.oid - JOIN pg_namespace dest_table_ns ON dest_table.relnamespace = dest_table_ns.oid - JOIN pg_attribute dest_column ON c.confrelid = dest_column.attrelid - WHERE c.contype = 'f'::char - AND source_table.relname = ? - AND n.nspname = ? - AND source_column.attnum = ANY(c.conkey) - AND dest_column.attnum = ANY(c.confkey)") - -(defmethod driver/describe-table-fks :redshift - [_ database table] - (set (for [fk (jdbc/query (sql-jdbc.conn/db->pooled-connection-spec database) - [fk-query (:name table) (:schema table)])] - {:fk-column-name (:fk-column-name fk) - :dest-table {:name (:dest-table-name fk) - :schema (:dest-table-schema fk)} - :dest-column-name (:dest-column-name fk)}))) - (defmethod driver/db-start-of-week :redshift [_] :sunday)