2014-05-05 23:13:06 +08:00
|
|
|
-- Function returning indexes for a table
|
2019-05-31 21:29:28 +08:00
|
|
|
CREATE OR REPLACE FUNCTION @extschema@.CDB_TableIndexes(REGCLASS)
|
2014-05-05 23:13:06 +08:00
|
|
|
RETURNS TABLE(index_name name, index_unique bool, index_primary bool, index_keys text array)
|
|
|
|
AS $$
|
|
|
|
|
|
|
|
SELECT pg_class.relname as index_name,
|
|
|
|
idx.indisunique as index_unique,
|
|
|
|
idx.indisprimary as index_primary,
|
|
|
|
ARRAY(
|
|
|
|
SELECT pg_get_indexdef(idx.indexrelid, k + 1, true)
|
|
|
|
FROM generate_subscripts(idx.indkey, 1) as k
|
|
|
|
ORDER BY k
|
|
|
|
) as index_keys
|
|
|
|
FROM pg_indexes,
|
|
|
|
pg_index as idx
|
|
|
|
JOIN pg_class
|
|
|
|
ON pg_class.oid = idx.indexrelid
|
|
|
|
WHERE pg_indexes.tablename = '' || $1 || ''
|
2020-11-24 00:04:49 +08:00
|
|
|
AND '' || $1 || '' IN (SELECT @extschema@.CDB_UserTables())
|
2014-06-06 17:02:51 +08:00
|
|
|
AND pg_class.relname=pg_indexes.indexname
|
|
|
|
;
|
2014-05-05 23:13:06 +08:00
|
|
|
|
2017-10-24 20:16:56 +08:00
|
|
|
$$ LANGUAGE SQL STABLE PARALLEL SAFE;
|
2014-05-05 23:13:06 +08:00
|
|
|
|
2014-06-06 17:33:34 +08:00
|
|
|
-- This is to migrate from pre-0.2.0 version
|
|
|
|
-- See http://github.com/CartoDB/cartodb-postgresql/issues/36
|
2019-05-31 21:29:28 +08:00
|
|
|
GRANT EXECUTE ON FUNCTION @extschema@.CDB_TableIndexes(REGCLASS) TO public;
|