SQL Complexity Estimator
This package provides a simple algorithm to calculate complexity of SQL expressions.
It's based on SQLGlot abstract syntax tree, so the provided SQL must be compatible with SQLGlot engines.
The rules are the following:
- +1 per join expression
- +1 per predicate after WHERE or HAVING
- +1 per CTE
- +1 per GROUP BY expression
- +1 per UNION or INTERSECT
- +1 per function call
- +1 per CASE expression
This package is inspired on the comments of this stack overflow thread.
Install
python -m pip install sql-complexity
poetry add sql-complexity
uv add sql-complexity
Run with uvx
uvx --refresh sql-complexity
Run from the CLI
sql-complexity some.sql
cat myfile.sql | sql-complexity
Using it in your code
from sql_complexity import SQLComplexityAssessment
assessor = SQLComplexityAssessment()
score = assessor.assess(contents)
print(score)
print(score.total)
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
sql_complexity-0.1.6.tar.gz
(4.7 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sql_complexity-0.1.6.tar.gz.
File metadata
- Download URL: sql_complexity-0.1.6.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.9.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fc028a3d3561b53099d593f1e63eb4a48e3e8acfeed6d45d16564d16ebbc6868
|
|
| MD5 |
fded6e08b8ef8c7bc78fc94e49fbcdba
|
|
| BLAKE2b-256 |
3ed47dd0572c190ae5d640dde2a39829d92afdf21d49f05dbcfdb6e713cba617
|
File details
Details for the file sql_complexity-0.1.6-py3-none-any.whl.
File metadata
- Download URL: sql_complexity-0.1.6-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.9.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
506f94e5f05c01f9c13228f9b449860e520a3f42145e8fe409721f4fd805f146
|
|
| MD5 |
69b2870b793eb3030b57130341e24b3a
|
|
| BLAKE2b-256 |
143530cbd4ef7ab4b6d324fd8e74e9fcf7a9e0e78531a584e3d834937e8e3531
|