Closed toxaus closed 1 year ago
Fixed: Try version 1.1.1.
new functionality union($query, 'DISTINCT') https://clickhouse.com/docs/en/sql-reference/statements/select/union/
Fixed: Try version 1.1.1.
new functionality union($query, 'DISTINCT') https://clickhouse.com/docs/en/sql-reference/statements/select/union/
Thank you for your super fast reaction. It works!
In case of multiple UNIONS with HAVING conditions inside, there is an error:
Query error: Code: 62. DB::Exception: Syntax error: failed at position 968 ('ALL'): ALL SELECT a, b, c Expected one of: token, Dot, UUID, DoubleColon, MOD, DIV, NOT, BETWEEN, LIKE, ILIKE, NOT LIKE, NOT ILIKE, IN, NOT IN, GLOBAL IN, GLOBAL NOT IN, IS, AND, OR, QuestionMark, alias, AS, WINDOW, ORDER BY, LIMIT, OFFSET, SETTINGS, UNION, EXCEPT, INTERSECT. (SYNTAX_ERROR) (version 22.7.1.2484 (official build))
It happens because of missing space before UNION keyword. Generated SQL looks like this:
https://github.com/sanchezzzhak/kak-clickhouse/blob/2cde1433ddc3814d05697b211f5512cef81a15e6/QueryBuilder.php#L305
I propose to change line 305 with:
$result .= 'UNION ' . ($union['all'] ? 'ALL ' : '') . '( ' . $unions[$i]['query'] . ' ) ';