sqlparse icon indicating copy to clipboard operation
sqlparse copied to clipboard

Option to insert a new line after some keywords

Open aisbergde opened this issue 4 years ago • 0 comments

on https://sqlparse.readthedocs.io/en/latest/api/ I can't find an option to insert a new line after some keywords like SELECT, FROM, LEFT JOIN, ON, ... Is it possible to implement this option or several options to do this? If not, what would be the best way to get the required result?

Example:

SELECT
DISTINCT
A = T1.B
, C = T1.D 
, T2.F AS E
, G = --some comment
--comment line 2
T1.H + T2.I 
FROM
aaa.bbb T1
LEFT JOIN
aaa.ccc T2
ON T1.bb = T2.bb

the need behind:

SQL Server supports Python. And it should be possible to use the sqlparse modul in sql server external scripts, to convert the code of SQL objects (views) in a more formal presentation where this is possible. This format should be more easy to parse to try to extract metadata of the view defintion.

From the examaple below the target will be some tables, one of them will be

Target SourceTable SourceColumn Statement
A aaa.bbb B NULL
C aaa.bbb D NULL
E aaa.ccc F NULL
G --some comment
--comment line 2
T1.H + T2.I

But I will do what I can do in TSQL, because I am a database developer and not a python developer

aisbergde avatar Sep 03 '20 08:09 aisbergde