andialbrecht / sqlparse

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

Different behaviour library and sqlformat.org #725

Open KoBOLL opened 1 year ago

KoBOLL commented 1 year ago

I am trying to parse an SQL query:

do $$
declare
  content_count int = 10;
begin
  /*comment*/
  select 1;
end; $$

sqlformat.org parse and highlight it correctly: image

But when I try to do it in Python:

import sqlparse

def parse(s: str):
    res = sqlparse.parse(s)
    print(res[0].tokens)

parse("""
do $$
declare
  content_count int = 10;
begin
  /*comment*/
  select 1;
end; $$""")

I get :

[<Newline ' ' at 0x7AB1C28A8408>, <Keyword 'do' at 0x7AB1C28A8468>, <Whitespace ' ' at 0x7AB1C28A84C8>, <Literal '$$ dec...' at 0x7AB1C28A8528>]

What am I doing wrong?