mathieubossaert / central2pg

Some PostgreSQL functions to retrieve data from an ODK Central server to PostgreSQL tables.
GNU General Public License v3.0
22 stars 9 forks source link

Random index naming generates one new index each time -> fills the database ! #13

Closed mathieubossaert closed 2 years ago

mathieubossaert commented 2 years ago

Waiting for fix : this command generates the script to drop duplicated indexes :

SELECT concat ('BEGIN;DROP INDEX IF EXISTS your_central_data_schema."',indexname,'";COMMIT;') FROM 
    pg_indexes
WHERE
    schemaname = 'your_central_data_schema'
    AND indexname NOT IN (
SELECT
    max(indexname)--, split_part(indexdef, ' ON ',2)
FROM
    pg_indexes
WHERE
    schemaname = 'your_central_data_schema'
    AND split_part(indexdef,' ON ',2) IS NOT NULL
    GROUP BY split_part(indexdef, ' ON ',2)
        )
        AND indexname ILIKE 'idx__%'