1

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;

1
  • IIRC, you need to use two separate scripts (that is CREATE INDEX CONCURRENTLY must be on its own in a script, otherwise Flyway can't run it without transaction) Commented Jun 25, 2021 at 16:45

1 Answer 1

2

Why are you using such an old version of flyway ? You should first upgrade your version of flyway, and then:

Create a configuration file for your script like V01_001__my_script.sql.conf where V01_001__my_script.sql is the name of your sql file.

and put this line inside:

executeInTransaction=false

That will disable the execution in a transaction for this script.

Sign up to request clarification or add additional context in comments.

2 Comments

There is a lot of old legacy code) When i started updating the version it caused a cascade of errors. Tomorrow i will try your advice)
There is new problem) Postgres cant run functions and procedure in non transactional mode

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.