-
Notifications
You must be signed in to change notification settings - Fork 275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Getting pq: syntax error at or near "transaction" when running migration with transaction:false #455
Comments
Taking a look at this, I've created similar migration: -- migrate:up transaction:false
drop index concurrently idx;
create index concurrently idx on test (id); I get a slightly different error which actually states it can't work within a transaction: % dbmate up
Applying: 20230831142614_error.sql
Error: pq: DROP INDEX CONCURRENTLY cannot run inside a transaction block Details:
Not got my test enviornment setup back up yet, I'll investigate more soon. |
I was able to reproduce this issue with the latest dbmate 2.7.0-main, against PostgreSQL 10.21:
Searching for that particular error turns up
And this issue came up again in #182. It looks like this is ultimately an issue with how The workaround is to create separate migration files for each Perhaps the migrations option section of the README could document this, including the various error string responses above so that people searching may be able to find the information? This is certainly a problem that has occurred repeatedly over the years, so I think there should be value in mentioning it clearly in the documentation. |
Duplicate of #126. |
does moving to pgx can solve this ? Or using some kind of (not perfect ) regex ( ;[end of line]) to separate statements and run them one by one? I think it can support a lot of use cases |
Moving to pgx is unlikely to solve this. The author of pgx, @jackc, created their own SQL migration tool named tern. And, they encountered this very same issue, because the problem is not one that can be safely resolved at the driver level, in Regular expressions alone cannot be used to create a fully correct SQL parser that could safely split any arbitrary SQL statement, although strictly limiting the splitting to
You can see what @jackc did in |
@dossy , I believe it can solve a lot of use cases for transaction:false, which is better then the current state. The Author states he want to keep things simple, supporting just basic statements could be good enough. Also, in Goose they use a custom annotation for complex statements. This also can be done on every statement in the transaction:false case.
For me its blocking this simple transaction:false migration:
If a few lines of code can add 70% statement support dont you think its a good addition? And of course not supporting multiline statements or harder statements in this mode will be added to the readme |
My personal preference is to not add anything that will break what currently is known to work, even if it's a really good addition. Personally, I value stability and reliability over feature completeness. I understand others feel differently; that's why there are so many varieties of products that do similar things. If someone can provide an implementation of a few lines of code that will not break every user's current migrations, with tests to prove such, we could all review it together and evaluate whether it is a good addition or not. |
Would there be interest in using pg_query to handle this? If that is used, then there should be no worry to statement complexity since that's using the actual Postgres parser itself under the hood. |
Description
Having
--migrate:up transaction:false
in a dbmate migration file produces a syntax error.
Steps To Reproduce
CREATE INDEX CONCURRENTLY ...
in a dbmate migrations file:dbmate --no-schema-dump up
.Actual Behavior
It seems this is some bug/limitation with the
pq
lib, but I just wanted to give a heads up.The text was updated successfully, but these errors were encountered: