andialbrecht / sqlparse

A non-validating SQL parser module for Python
BSD 3-Clause "New" or "Revised" License
3.77k stars 701 forks source link

Still being maintained? #624

Open ConstantinoSchillebeeckx opened 3 years ago

ConstantinoSchillebeeckx commented 3 years ago

Is this project still being maintained? There are 172 open issues, 18 PRs and the last commit was in Dec 2020 :(

andialbrecht commented 3 years ago

yes, just busy at work

Am Mi., 26. Mai 2021 um 14:35 Uhr schrieb Constantino Schillebeeckx < @.***>:

Is this project still being maintained? There are 172 open issues, 18 PRs and the last commit was in Dec 2020 :(

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/andialbrecht/sqlparse/issues/624, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAGIIBBBF5BCF455G2SEQ3TPTTILANCNFSM45R57LQA .

ConstantinoSchillebeeckx commented 3 years ago

Anything we can do to help out?

tobymao commented 3 years ago

I've created a full sql parser / transpiler from scratch and am actively developing it. It has a full tokenizer / parser and doens't use regex.

It can transpile from various sql dialects to other sql dialects as well as things like formatting and parsing things out.

https://github.com/tobymao/sqlglot

f-raffa commented 3 years ago

Anything we can do to help out?

Yeah, actually if there was something we could do to help out I'd like to contribute... Because of my job I worked I lot on the code and I would also have some changes to propose for discussion. Would you be interested?

f-raffa commented 3 years ago

I've created a full sql parser / transpiler from scratch and am actively developing it. It has a full tokenizer / parser and doens't use regex.

It can transpile from various sql dialects to other sql dialects as well as things like formatting and parsing things out.

https://github.com/tobymao/sqlglot

@tobymao: I checked your project and I was wondering if you were planning to integrate any formatting capabilities to it?

tobymao commented 3 years ago

@f-raffa i have a pretty mode, and you can chose the indent and padding levels

f-raffa commented 3 years ago

@tobymao: I see. I'd like simply to parse and format a sql statement without transpiling it. Does your app provide such a functionality? May you please share the command that I should use to do that?

tobymao commented 3 years ago

sqlglot.transpile("select * from x", read='presto', pretty=True)

AhlamHani commented 2 months ago

@tobymao this helped me to fix a bug!!

    sql = sqlparse.format(sql, strip_whitespace=True, strip_comments=True).strip()
    sql = sqlglot.transpile(sql, read=Dialects.MYSQL, write=Dialects.MYSQL, pretty=True)[0]

the reason that keyword_case='upper' in sqlparse has a bug, it does not distinguish between table names and SQL commands, so your table name can be transformed to uppercase in case your table is named like a sql command, e.g. "transaction"

here is my SQL query:


SELECT
    t.name AS tenant_name
FROM
    tenant t
        JOIN
    salik_account sa ON t.id = sa.tenant_id
        JOIN
    transaction tr ON sa.id = tr.salik_account_id
WHERE
    tr.status = 'completed';

using sqlparse.format(sql, strip_whitespace=True, strip_comments=True, keyword_case='upper').strip() also converted transaction table to TRANSACTION, sqlglot.transpile fixed the issue