There is only one truth. It is the source.

Create an index if it does not exist

May 15, 2014

Tags: postgresql

DO $$
BEGIN

IF NOT EXISTS (
    SELECT 1
    FROM pg_indexes
    WHERE indexname = 'profile_profile_middle_name'
    AND schemaname = 'public'
    ) THEN

    CREATE INDEX profile_profile_middle_name
    ON profile_profile
    USING btree
    (middle_name COLLATE pg_catalog."default" );
END IF;

END$$;