Author |
Message |
gemisigo
Joined: 11 Mar 2010 Posts: 2165
|
|
Formatting for MySQL UPDATE statement |
|
The default formatting rule for UPDATE statements in MySQL is:
 |
 |
UPDATE
...
SET
... = ...,
...
WHERE
... = ...
AND ...
OR ...
ORDER BY
...,
...
LIMIT ...;
|
That rule leaves the following code with joined tables:
 |
 |
UPDATE
verseny.palyaelem_adatok AS u INNER JOIN tavolsagok AS t ON t.ronk = u.ronk
SET u.tavolsag_sum = t.tavolsag_sum
WHERE 1 = 1;
|
mostly as
 |
 |
UPDATE
verseny.palyaelem_adatok AS u INNER JOIN tavolsagok AS t ON t.ronk = u.ronk
SET
u.tavolsag_sum = t.tavolsag_sum
WHERE
1 = 1;
|
I tried to merge it with the my SELECT rule of:
 |
 |
SELECT
... AS ...
,...
INTO
...
,...
FROM
... AS ...
,...
JOIN
...
ON ... = ...
AND ...
OR ...
WHERE ... = ...
AND ...
OR ...
GROUP BY
...
,...
HAVING
...
,...
ORDER BY
...
,...
LIMIT ...;
|
and ended up with this:
 |
 |
UPDATE
... AS ...
,...
JOIN
...
ON ... = ...
AND ...
OR ...
SET ... = ...
WHERE ... = ...
AND ...
OR ...
ORDER BY
...
LIMIT ...;
|
But this formats the above code as:
 |
 |
UPDATE
verseny.palyaelem_adatok AS u INNER
JOIN
tavolsagok AS t
ON t.ronk = u.ronk
SET u.tavolsag_sum = t.tavolsag_sum
WHERE 1 = 1;
|
leaving the INNER keyword on a wrong line, which obviously was not my intention. The same fragment of rule (the part affecting JOINs) works as expected, that is, moving INNER/LEFT OUTER/RIGHT OUTER/etc together with the JOIN keyword. Any ideas about what's missing?
|
|
Sun Jul 16, 2017 6:17 am |
|
 |
SysOp
Site Admin
Joined: 26 Nov 2006 Posts: 7948
|
|
|
|
Do you have a separate formatting rule for JOIN. If yes, it might be interfering.
|
|
Sun Jul 16, 2017 12:47 pm |
|
 |
gemisigo
Joined: 11 Mar 2010 Posts: 2165
|
|
|
|
No. The only other rule having the word JOIN in it is for SELECT. Could that be interfering? Not that it's something I could afford to have disabled or missing, to be honest.
|
|
Sun Jul 16, 2017 12:53 pm |
|
 |
SysOp
Site Admin
Joined: 26 Nov 2006 Posts: 7948
|
|
|
|
It shouldn't, the first keyboard is different.
What do you get if you add additional ... in front of JOIN?
|
|
Sun Jul 16, 2017 12:56 pm |
|
 |
gemisigo
Joined: 11 Mar 2010 Posts: 2165
|
|
|
|
It got worse:
 |
 |
UPDATE
verseny.palyaelem_adatok AS u INNER JOIN
...
tavolsagok AS t
ON t.ronk = u.ronk
SET u.tavolsag_sum = t.tavolsag_sum
WHERE 1 = 1;
|
|
|
Sun Jul 16, 2017 12:58 pm |
|
 |
SysOp
Site Admin
Joined: 26 Nov 2006 Posts: 7948
|
|
|
|
I tried brute force method and added a separate rule for INNER JOIN to place it on a new line
 |
 |
...
INNER JOIN
... |
And conceptually it does kind of what you want, except that it creates wrong indent for the INNER JOIN. I feel like it's reaching the limits of what the code formatting can do using the existing rules processing system without internal programmatic changes.
|
|
Mon Jul 17, 2017 7:50 am |
|
 |
gemisigo
Joined: 11 Mar 2010 Posts: 2165
|
|
|
|
I guess I'll just live with one thing malformed and that will be UPDATE statements. I don't have many of those. Thanks for figuring this out.
|
|
Mon Jul 17, 2017 10:06 am |
|
 |
|