|
SoftTree Technologies
Technical Support Forums
|
|
Author |
Message |
gemisigo
Joined: 11 Mar 2010 Posts: 2141
|
|
[12.1.279 Pro] - Formatting CROSS JOINs (MariaDB) |
|
I have the following formatting rule for SELECT:
|
|
SELECT ... AS ...
,... = ...
FROM ... AS ...
,...
JOIN ... ON ... = ... AND ... OR ...
WHERE ... = ...
AND ...
OR ...
GROUP BY ...
,...
HAVING ...
,...
ORDER BY ...
,...
LIMIT ...
INTO ...
,...;
|
and given is the following SELECT statement:
|
|
SELECT t.`name` AS `tracker_name` ,isf.`status_name` AS `status_name$from`
,ist.`status_name` AS `status_name$to` ,tea.`activity_name`
,t.`id` AS `tracker_id` ,isf.`issue_status_id` AS `issue_status_id$from`
,ist.`issue_status_id` AS `issue_status_id$to` ,tea.`activity_id`
FROM `cte_issue_status` AS isf CROSS JOIN `cte_issue_status` AS ist
CROSS JOIN `tt_time_entry_activity` AS tea CROSS JOIN `trackers` AS t
WHERE t.`name` = 'whatever';
|
I'd expect the rule to transform this above into something like this:
|
|
SELECT t.`name` AS `tracker_name`
,isf.`status_name` AS `status_name$from`
,ist.`status_name` AS `status_name$to`
,tea.`activity_name`
,t.`id` AS `tracker_id`
,isf.`issue_status_id` AS `issue_status_id$from`
,ist.`issue_status_id` AS `issue_status_id$to`
,tea.`activity_id`
FROM `cte_issue_status` AS isf
CROSS JOIN `cte_issue_status` AS ist
CROSS JOIN `tt_time_entry_activity` AS tea
CROSS JOIN `trackers` AS t
WHERE t.`name` = 'whatever';
|
However, it ends up like this instead:
|
|
SELECT t.`name` AS `tracker_name`
,isf.`status_name` AS `status_name$from`
,ist.`status_name` AS `status_name$to`
,tea.`activity_name`
,t.`id` AS `tracker_id`
,isf.`issue_status_id` AS `issue_status_id$from`
,ist.`issue_status_id` AS `issue_status_id$to`
,tea.`activity_id`
FROM `cte_issue_status` AS isf
CROSS JOIN `cte_issue_status` AS ist
CROSS JOIN `tt_time_entry_activity` AS tea CROSS JOIN `trackers` AS t
WHERE t.`name` = 'whatever';
|
It seems that the first CROSS JOIN somehow gets where it should be but the subsequent ones are messed up. I tried helping by moving the CJs to separate lines but the result only got slightly better. Formatting preserved the separate lines and even the aliases were aligned, but the CROSS JOIN keyword was consistently moved to the beginning of the line for every CJ but the first one.
|
|
SELECT t.`name` AS `tracker_name`
,isf.`status_name` AS `status_name$from`
,ist.`status_name` AS `status_name$to`
,tea.`activity_name`
,t.`id` AS `tracker_id`
,isf.`issue_status_id` AS `issue_status_id$from`
,ist.`issue_status_id` AS `issue_status_id$to`
,tea.`activity_id`
FROM `cte_issue_status` AS isf
CROSS JOIN `cte_issue_status` AS ist
CROSS JOIN `tt_time_entry_activity` AS tea
CROSS JOIN `trackers` AS t
WHERE t.`name` = 'whatever';
|
Any hints on what am I doing wrong here? I can replace the CROSS JOIN with commas, which would format properly, but even if there's no accounting for taste, that code will be objectively harder to spot CROSS JOINs (and the potential danger they "provide") at a quick glance.
|
|
Thu Oct 20, 2022 10:18 am |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|