Skip to content

PostgresqlConnectionManager SplitScriptIntoCommands isn't splitting the script, causing unexpected transaction errors #11

@mgkeen

Description

@mgkeen

I noticed this when trying to create a script with multiple DROP INDEX CONCURRENTLY statements in it. I was getting weird transaction errors even when not running in a transaction.

The regex pattern is ^\\s*;\\s*$. The ^ is causing this to only match if a ; is on a line by itself surrounded by whitespace.

That means the following script is being executed as a single statement when it should be separated into multiple statements. By executing as a single statement you get the error DROP INDEX CONCURRENTLY must be first action in transaction for index_2:

DROP INDEX CONCURRENTLY index_1;
DROP INDEX CONCURRENTLY index_2;
DROP INDEX CONCURRENTLY index_3;

I'm sure there's some edge cases for this as well to avoid picking up ; from within strings etc. I'll put up a PR to resolve the issue as best I can soon.

For anyone else getting this problem right now, as a workaround you can do the following. It looks silly but it will match the regex and cause the script to be split properly:

DROP INDEX CONCURRENTLY individual_full_name_trgm
;
DROP INDEX CONCURRENTLY individual_name_trgm
;
DROP INDEX CONCURRENTLY individual_phone_trgm
;

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions