I want do something like:
CREATE OR REPLACE FUNCTION __column_exists(TEXT, TEXT, TEXT) RETURNS bool as $$
SELECT exists(SELECT 1 FROM information_schema.columns WHERE (table_schema, table_name, column_name) = ($1, $2, $3));
$$ language sql STRICT;
DO $$ BEGIN IF __column_exists('public', 'table_name', 'column_name') THEN
CREATE INDEX CONCURRENTLY IF NOT EXISTS column_idx ON table_name USING btree (column_name);
END IF; END; $$;
But there is
ERROR: CREATE INDEX CONCURRENTLY cannot run inside a transaction block
It works fine if I write only
CREATE INDEX CONCURRENTLY IF NOT EXISTS column_idx ON table_name USING btree (column_name);
How can I preserve the condition for the existence of a column?
Flyway 4.2.0;
CREATE INDEX CONCURRENTLYmust be on its own in a script, otherwise Flyway can't run it without transaction)