I am really enjoying this!
Ok, latest version. Kem’s complex code:
[code]–
– Some test sql
– with a multi-line comment
– and stuff
with my_with_1 as (
select col1, col2, col3 as “col 3”
from (
select * from table2) as sub_table1 where
id = ‘some string’
)
with my_with_2 as (
select some_function(param1, param2, ‘string param’)
from table3 t3
left join table4 as t4 on (t4.id = t4.table4_id)
where upper(lower(string_function(‘some
long
string’, otherparam))) like my_with_1.col1
)
/* Here come
the select statements, but not here
select * from table1 where i = 4;
*/
(
select col1, col2, col3 as " select "
from my_with_2 – using my_with_2 here
right join table5 t5 – comment in the middle of join
on (
select distinct * from table6, table7 where table6.table7_id = table7.id
) where
t5 = some_other_function(
param1, param
)
group by col3, col2, col1
order by col1
limit 5 offset 4
) union
(
– just a copy of the one above
select col1, col2, col3 as " select "
from my_with_1 – using my_with_1 here
right join table5 t5 – comment in the middle of join
on (
select distinct * from table6, table7 where table6.table7_id = table7.id
) where
t5 = some_other_function(
param1, param
)
group by col3, col2, col1
order by col1
limit 5 offset 4
)[/code]
The output from my formatter:
[code]–
– Some test sql
– with a multi-line comment
– and stuff
WITH my_with_1 AS (SELECT
col1,
col2,
col3 AS “col 3”
FROM
(SELECT
*
FROM
table2) AS sub_table1
WHERE
id = ‘some string’ )
WITH my_with_2 AS (SELECT
some_function(param1,
param2,
‘string param’)
FROM
table3 t3
LEFT JOIN table4 AS t4 ON (t4.id = t4.table4_id)
WHERE
upper(lower(string_function(‘some long string’,
otherparam)))
LIKE my_with_1.col1 )
/* Here come
the select statements, but not here
select * from table1 where i = 4;
*/
(SELECT
col1,
col2,
col3 AS " select "
FROM
my_with_2 – using my_with_2 here
RIGHT JOIN table5 t5 – comment in the middle of join
ON (SELECT
distinct *
FROM
table6,
table7
WHERE
table6.table7_id = table7.id )
WHERE
t5 = some_other_function( param1,
param )
GROUP BY
col3,
col2,
col1
ORDER BY
col1
LIMIT 5 OFFSET 4 )
UNION
( – just a copy of the one above
SELECT
col1,
col2,
col3 AS " select "
FROM
my_with_1 – using my_with_1 here
RIGHT JOIN table5 t5 – comment in the middle of join
ON (SELECT
distinct *
FROM
table6,
table7
WHERE
table6.table7_id = table7.id )
WHERE
t5 = some_other_function( param1,
param )
GROUP BY
col3,
col2,
col1
ORDER BY
col1
LIMIT 5 OFFSET 4 )[/code]
Latest version here: sqlFormatter