sql-metadata icon indicating copy to clipboard operation
sql-metadata copied to clipboard

Parser.columns has bug

Open AliM1988 opened this issue 1 year ago • 0 comments

Bug that I see, it cant detect some columns:

from sql_metadata import Parser

def extract_columns_from_schema(schema_string):
    # Initialize the parser with the schema string
    parser = Parser(schema_string)

    # Extract columns using sql_metadata
    columns = parser.columns

    return columns

# Example usage:
schema_string = """
CREATE TABLE accounts (
            id INTEGER,     /* comment */
            username TEXT UNIQUE,
            status TEXT,
            online_at INTEGER,
            hash TEXT UNIQUE,
            uid TEXT UNIQUE,
            test INTEGER,
            usage INTEGER,
            
            PRIMARY KEY (id)
        )
"""

extracted_columns = extract_columns_from_schema(schema_string)
print(extracted_columns)

column username cant be detect because previous line has comment. columns hash uid usage cant be detect because they are keyword, while SQLite create these column correctly.

It is stranger different response in ubuntu and Google Colab. In my ubuntu hashis detected . In both, sql_metadata==2.12.0 is installed

I checked via parser.tokens: ubuntu: value=hash,is_keyword=False Google Colab= value=hash,is_keyword=True

AliM1988 avatar Jul 05 '24 12:07 AliM1988