Parses an SQL query. Returns syntax errors. Does not check for catalog errors (incorrect table names, etc). Currently only supports DuckDB. Args: query (str): The SQL query to parse. dialect (str): The dialect of the SQL query. Returns: tuple[SqlParseResult,
(
query: str, dialect: str
)
| 55 | |
| 56 | |
| 57 | def parse_sql( |
| 58 | query: str, dialect: str |
| 59 | ) -> tuple[SqlParseResult | None, str | None]: |
| 60 | """Parses an SQL query. Returns syntax errors. |
| 61 | Does not check for catalog errors (incorrect table names, etc). |
| 62 | Currently only supports DuckDB. |
| 63 | |
| 64 | Args: |
| 65 | query (str): The SQL query to parse. |
| 66 | dialect (str): The dialect of the SQL query. |
| 67 | |
| 68 | Returns: |
| 69 | tuple[SqlParseResult, str]: SqlParseResult and unexpected errors |
| 70 | """ |
| 71 | dialect = dialect.strip().lower() |
| 72 | |
| 73 | try: |
| 74 | if "duckdb" in dialect: |
| 75 | return _parse_sql_duckdb(query) |
| 76 | else: |
| 77 | return None, "Unsupported dialect: " + dialect |
| 78 | except Exception as e: |
| 79 | return None, str(e) |
| 80 | |
| 81 | |
| 82 | class DuckDBParseError(msgspec.Struct): |
searching dependent graphs…