SoftTree Technologies SoftTree Technologies
Technical Support Forums
RegisterSearchFAQMemberlistUsergroupsLog in
[12.1.279 Pro] - Formatting CROSS JOINs (MariaDB)

 
Reply to topic    SoftTree Technologies Forum Index » SQL Assistant View previous topic
View next topic
[12.1.279 Pro] - Formatting CROSS JOINs (MariaDB)
Author Message
gemisigo



Joined: 11 Mar 2010
Posts: 2141

Post [12.1.279 Pro] - Formatting CROSS JOINs (MariaDB) Reply with quote
I have the following formatting rule for SELECT:
Code:

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:
Code:

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:
Code:

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:
Code:

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.
Code:

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 View user's profile Send private message
Display posts from previous:    
Reply to topic    SoftTree Technologies Forum Index » SQL Assistant All times are GMT - 4 Hours
Page 1 of 1

 
Jump to: 
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


 

 

Powered by phpBB © 2001, 2005 phpBB Group
Design by Freestyle XL / Flowers Online.