Having multiple statements in migration throws error on ClickHouse #360
Replies: 8 comments 2 replies
-
I am also stacked with this problem. It seems that clickhouse http client has multiquery support https://clickhouse.tech/docs/en/interfaces/cli/#command-line-options but CH go client still doesn't support multiqueries. My issue in clickhouse go client repo is opened without any answers for several month ClickHouse/clickhouse-go#351 upd: I did a little research - it seems that CH multiquery support is made on cli client side (https://github.com/ClickHouse/ClickHouse/blob/master/programs/client/Client.cpp#L1099) and there is no server-side multiquery support. So the only way is to split query on tokens in dbmate or in go driver directly. |
Beta Was this translation helpful? Give feedback.
-
It sounds like the easiest way to solve this is probably to fix it in the ClickHouse go client, since our other drivers support multi statements natively. It would be possible (but not trivial) to add a SQL parser and send statements one at a time (but not sure that is a good idea). |
Beta Was this translation helpful? Give feedback.
-
Yeah it seems like clickhouse-go is the better place for this as it requires parsing the SQL. |
Beta Was this translation helpful? Give feedback.
-
Unfortunately there will be no multiquery support on the clickhouse-go driver side |
Beta Was this translation helpful? Give feedback.
-
In that case, it might be a showstopper. I'm not very excited about adding SQL parsing logic to dbmate, it would be a lot of work to maintain over time, with inconsistencies between database plugins, etc. So unless there is upstream support for multiquery in the sql driver, we probably can't support it in dbmate. |
Beta Was this translation helpful? Give feedback.
-
I have not written a lot of golang but I like the approach taken by golang-migrate https://github.com/golang-migrate/migrate/blob/master/database/clickhouse/clickhouse.go#L139 It simply splits the statements on the This is not as robust as adding proper SQL parsing logic but it mentions that in the notes. https://github.com/golang-migrate/migrate/tree/master/database/clickhouse#notes
In my case, multiple statement support is a dealbreaker. Would the approach taken by golang-migrate be a good middle ground here? |
Beta Was this translation helpful? Give feedback.
-
Goose uses a special comment for multiple statements that cannot be split with
|
Beta Was this translation helpful? Give feedback.
-
Hello. Why you can't just introduce special strings like |
Beta Was this translation helpful? Give feedback.
-
I have a simple migration to test on ClickHouse like this
Running the above migration throws this error
I'm guess either there's an option needed to set when connecting to the DB, or maybe ClickHouse doesn't support multi-statement query. Perhaps dbmate can split the query up and send them one by one?
Beta Was this translation helpful? Give feedback.
All reactions