sqlchecker 0.3.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. sqlchecker-0.3.1/.gitignore +186 -0
  2. sqlchecker-0.3.1/.readthedocs.yaml +35 -0
  3. sqlchecker-0.3.1/LICENSE +21 -0
  4. sqlchecker-0.3.1/Makefile +56 -0
  5. sqlchecker-0.3.1/PKG-INFO +153 -0
  6. sqlchecker-0.3.1/README.md +130 -0
  7. sqlchecker-0.3.1/datasets/catalogs/constraints.json +343 -0
  8. sqlchecker-0.3.1/datasets/catalogs/miedema.json +392 -0
  9. sqlchecker-0.3.1/datasets/sql/constraints.sql +38 -0
  10. sqlchecker-0.3.1/datasets/sql/miedema.sql +85 -0
  11. sqlchecker-0.3.1/docs/Makefile +20 -0
  12. sqlchecker-0.3.1/docs/conf.py +40 -0
  13. sqlchecker-0.3.1/docs/index.rst +38 -0
  14. sqlchecker-0.3.1/docs/make.bat +35 -0
  15. sqlchecker-0.3.1/docs/requirements.txt +1 -0
  16. sqlchecker-0.3.1/pyproject.toml +33 -0
  17. sqlchecker-0.3.1/requirements.txt +17 -0
  18. sqlchecker-0.3.1/src/sqlchecker/__init__.py +58 -0
  19. sqlchecker-0.3.1/src/sqlchecker/detectors/__init__.py +103 -0
  20. sqlchecker-0.3.1/src/sqlchecker/detectors/base.py +44 -0
  21. sqlchecker-0.3.1/src/sqlchecker/detectors/complications.py +375 -0
  22. sqlchecker-0.3.1/src/sqlchecker/detectors/logical.py +732 -0
  23. sqlchecker-0.3.1/src/sqlchecker/detectors/semantic.py +289 -0
  24. sqlchecker-0.3.1/src/sqlchecker/detectors/syntax.py +1140 -0
  25. sqlchecker-0.3.1/test_detector.py +36 -0
  26. sqlchecker-0.3.1/tests/1_syn/test_001_ambiguous_column.py +42 -0
  27. sqlchecker-0.3.1/tests/1_syn/test_003_undefined_column.py +45 -0
  28. sqlchecker-0.3.1/tests/1_syn/test_004_undefined_function.py +46 -0
  29. sqlchecker-0.3.1/tests/1_syn/test_005_undefined_parameter.py +43 -0
  30. sqlchecker-0.3.1/tests/1_syn/test_006_undefined_object.py +43 -0
  31. sqlchecker-0.3.1/tests/1_syn/test_007_invalid_schema_names.py +43 -0
  32. sqlchecker-0.3.1/tests/1_syn/test_008_misspellings.py +49 -0
  33. sqlchecker-0.3.1/tests/1_syn/test_012_is_where_not_applicable.py +49 -0
  34. sqlchecker-0.3.1/tests/1_syn/test_013_data_type_mismatch.py +50 -0
  35. sqlchecker-0.3.1/tests/1_syn/test_014_aggregate_function_outside_select_or_having.py +43 -0
  36. sqlchecker-0.3.1/tests/1_syn/test_015_nested_aggregate_functions.py +47 -0
  37. sqlchecker-0.3.1/tests/1_syn/test_016_extraneous_omitted_grouping_column.py +47 -0
  38. sqlchecker-0.3.1/tests/1_syn/test_017_having_without_group_by.py +59 -0
  39. sqlchecker-0.3.1/tests/1_syn/test_018_too_many_columns_in_subquery.py +42 -0
  40. sqlchecker-0.3.1/tests/1_syn/test_021_using_where_twice.py +53 -0
  41. sqlchecker-0.3.1/tests/1_syn/test_022_omitted_from.py +51 -0
  42. sqlchecker-0.3.1/tests/1_syn/test_024_036_additional_omitted_semicolons.py +60 -0
  43. sqlchecker-0.3.1/tests/1_syn/test_024_comparison_with_null.py +40 -0
  44. sqlchecker-0.3.1/tests/1_syn/test_026_duplicate_clause.py +43 -0
  45. sqlchecker-0.3.1/tests/1_syn/test_029_keywords_order.py +36 -0
  46. sqlchecker-0.3.1/tests/1_syn/test_032_033_curly_square_or_unmatched_brackets.py +68 -0
  47. sqlchecker-0.3.1/tests/1_syn/test_035_nonstandard_operators.py +31 -0
  48. sqlchecker-0.3.1/tests/2_sem/test_038_tautological_inconsistent_expressions.py +117 -0
  49. sqlchecker-0.3.1/tests/2_sem/test_039_distinct_sum_avg.py +51 -0
  50. sqlchecker-0.3.1/tests/2_sem/test_050_constant_column_output.py +35 -0
  51. sqlchecker-0.3.1/tests/2_sem/test_051_duplicate_column_output.py +58 -0
  52. sqlchecker-0.3.1/tests/3_log/test_058_join_on_incorrect_table.py +170 -0
  53. sqlchecker-0.3.1/tests/3_log/test_059_join_when_join_needs_to_be_omitted.py +171 -0
  54. sqlchecker-0.3.1/tests/3_log/test_062_missing_join.py +171 -0
  55. sqlchecker-0.3.1/tests/3_log/test_067_wildcards_without_like.py +60 -0
  56. sqlchecker-0.3.1/tests/3_log/test_068_069_wrong_invalid_wildcard.py +85 -0
  57. sqlchecker-0.3.1/tests/3_log/test_070_extraneous_column_in_select.py +127 -0
  58. sqlchecker-0.3.1/tests/3_log/test_071_missing_column_from_select.py +127 -0
  59. sqlchecker-0.3.1/tests/3_log/test_072_missing_distinct_from_select.py +90 -0
  60. sqlchecker-0.3.1/tests/3_log/test_073_missing_as_from_select.py +89 -0
  61. sqlchecker-0.3.1/tests/3_log/test_112_118_missing_extraneous_where_clause.py +74 -0
  62. sqlchecker-0.3.1/tests/3_log/test_113_119_missing_extraneous_group_by_clause.py +74 -0
  63. sqlchecker-0.3.1/tests/3_log/test_114_120_missing_extraneous_having_clause.py +77 -0
  64. sqlchecker-0.3.1/tests/3_log/test_115_121_missing_extraneous_order_by_clause.py +79 -0
  65. sqlchecker-0.3.1/tests/3_log/test_116_121_123_missing_extraneous_incorrect_limit_clause.py +80 -0
  66. sqlchecker-0.3.1/tests/3_log/test_117_122_missing_extraneous_incorrect_offset_clause.py +85 -0
  67. sqlchecker-0.3.1/tests/4_com/test_096_unnecessary_distinct_in_select.py +38 -0
  68. sqlchecker-0.3.1/tests/4_com/test_102_like_without_wildcards.py +34 -0
  69. sqlchecker-0.3.1/tests/4_com/test_106_unnecessary_distinct_in_aggregate_function.py +79 -0
  70. sqlchecker-0.3.1/tests/4_com/test_109_group_by_with_singleton_groups.py +54 -0
  71. sqlchecker-0.3.1/tests/4_com/test_111_group_by_can_be_replaced_by_distinct.py +47 -0
  72. sqlchecker-0.3.1/tests/4_com/test_114_order_by_in_subquery.py +42 -0
  73. sqlchecker-0.3.1/tests/4_com/test_126_unused_cte.py +44 -0
  74. sqlchecker-0.3.1/tests/__init__.py +46 -0
@@ -0,0 +1,186 @@
1
+ # CUSTOM
2
+ test_q.sql
3
+ test_s?.sql
4
+ .codex
5
+
6
+ # Byte-compiled / optimized / DLL files
7
+ __pycache__/
8
+ *.py[cod]
9
+ *$py.class
10
+
11
+ # C extensions
12
+ *.so
13
+
14
+ # Distribution / packaging
15
+ .Python
16
+ build/
17
+ develop-eggs/
18
+ dist/
19
+ downloads/
20
+ eggs/
21
+ .eggs/
22
+ lib/
23
+ lib64/
24
+ parts/
25
+ sdist/
26
+ var/
27
+ wheels/
28
+ share/python-wheels/
29
+ *.egg-info/
30
+ .installed.cfg
31
+ *.egg
32
+ MANIFEST
33
+
34
+ # PyInstaller
35
+ # Usually these files are written by a python script from a template
36
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
37
+ *.manifest
38
+ *.spec
39
+
40
+ # Installer logs
41
+ pip-log.txt
42
+ pip-delete-this-directory.txt
43
+
44
+ # Unit test / coverage reports
45
+ htmlcov/
46
+ .tox/
47
+ .nox/
48
+ .coverage
49
+ .coverage.*
50
+ .cache
51
+ nosetests.xml
52
+ coverage.xml
53
+ *.cover
54
+ *.py,cover
55
+ .hypothesis/
56
+ .pytest_cache/
57
+ cover/
58
+
59
+ # Translations
60
+ *.mo
61
+ *.pot
62
+
63
+ # Django stuff:
64
+ *.log
65
+ local_settings.py
66
+ db.sqlite3
67
+ db.sqlite3-journal
68
+
69
+ # Flask stuff:
70
+ instance/
71
+ .webassets-cache
72
+
73
+ # Scrapy stuff:
74
+ .scrapy
75
+
76
+ # Sphinx documentation
77
+ docs/_build/
78
+
79
+ # PyBuilder
80
+ .pybuilder/
81
+ target/
82
+
83
+ # Jupyter Notebook
84
+ .ipynb_checkpoints
85
+
86
+ # IPython
87
+ profile_default/
88
+ ipython_config.py
89
+
90
+ # pyenv
91
+ # For a library or package, you might want to ignore these files since the code is
92
+ # intended to run in multiple environments; otherwise, check them in:
93
+ # .python-version
94
+
95
+ # pipenv
96
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
97
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
98
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
99
+ # install all needed dependencies.
100
+ #Pipfile.lock
101
+
102
+ # UV
103
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
104
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
105
+ # commonly ignored for libraries.
106
+ #uv.lock
107
+
108
+ # poetry
109
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
110
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
111
+ # commonly ignored for libraries.
112
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
113
+ #poetry.lock
114
+
115
+ # pdm
116
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
117
+ #pdm.lock
118
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
119
+ # in version control.
120
+ # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
121
+ .pdm.toml
122
+ .pdm-python
123
+ .pdm-build/
124
+
125
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
126
+ __pypackages__/
127
+
128
+ # Celery stuff
129
+ celerybeat-schedule
130
+ celerybeat.pid
131
+
132
+ # SageMath parsed files
133
+ *.sage.py
134
+
135
+ # Environments
136
+ .env
137
+ .venv
138
+ env/
139
+ venv/
140
+ ENV/
141
+ env.bak/
142
+ venv.bak/
143
+
144
+ # Spyder project settings
145
+ .spyderproject
146
+ .spyproject
147
+
148
+ # Rope project settings
149
+ .ropeproject
150
+
151
+ # mkdocs documentation
152
+ /site
153
+
154
+ # mypy
155
+ .mypy_cache/
156
+ .dmypy.json
157
+ dmypy.json
158
+
159
+ # Pyre type checker
160
+ .pyre/
161
+
162
+ # pytype static type analyzer
163
+ .pytype/
164
+
165
+ # Cython debug symbols
166
+ cython_debug/
167
+
168
+ # PyCharm
169
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
170
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
171
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
172
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
173
+ #.idea/
174
+
175
+ # Ruff stuff:
176
+ .ruff_cache/
177
+
178
+ # PyPI configuration file
179
+ .pypirc
180
+
181
+ <<<<<<< Updated upstream
182
+ # VS Code
183
+ .vscode/
184
+ =======
185
+ .vscode
186
+ >>>>>>> Stashed changes
@@ -0,0 +1,35 @@
1
+ # Read the Docs configuration file for Sphinx projects
2
+ # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
3
+
4
+ # Required
5
+ version: 2
6
+
7
+ # Set the OS, Python version and other tools you might need
8
+ build:
9
+ os: ubuntu-22.04
10
+ tools:
11
+ python: "3.11"
12
+ # You can also specify other tool versions:
13
+ # nodejs: "20"
14
+ # rust: "1.70"
15
+ # golang: "1.20"
16
+
17
+ # Build documentation in the "docs/" directory with Sphinx
18
+ sphinx:
19
+ configuration: docs/conf.py
20
+ # You can configure Sphinx to use a different builder, for instance use the dirhtml builder for simpler URLs
21
+ # builder: "dirhtml"
22
+ # Fail on all warnings to avoid broken references
23
+ # fail_on_warning: true
24
+
25
+ # Optionally build your docs in additional formats such as PDF and ePub
26
+ # formats:
27
+ # - pdf
28
+ # - epub
29
+
30
+ # Optional but recommended, declare the Python requirements required
31
+ # to build your documentation
32
+ # See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
33
+ python:
34
+ install:
35
+ - requirements: docs/requirements.txt
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) [2025] [Davide Ponzini, Davide Miggiano]
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,56 @@
1
+ ########## Makefile start ##########
2
+ # Type: PyPi
3
+ # Author: Davide Ponzini
4
+
5
+ NAME=sqlchecker
6
+ VENV=./venv
7
+ REQUIREMENTS=requirements.txt
8
+
9
+ ifeq ($(OS),Windows_NT)
10
+ VENV_BIN=$(VENV)/Scripts
11
+ else
12
+ VENV_BIN=$(VENV)/bin
13
+ endif
14
+
15
+ .PHONY: install build uninstall documentation test upload download clean coverage
16
+
17
+ install: uninstall build
18
+ $(VENV_BIN)/python -m pip install ./dist/*.whl
19
+
20
+ $(VENV):
21
+ python -m venv --clear $(VENV)
22
+ touch -a $(REQUIREMENTS)
23
+ $(VENV_BIN)/python -m pip install --upgrade -r $(REQUIREMENTS)
24
+
25
+ $(VENV)_upgrade: $(VENV)
26
+ $(VENV_BIN)/python -m pip install --upgrade -r $(REQUIREMENTS)
27
+
28
+ build: $(VENV)
29
+ rm -rf dist/
30
+ $(VENV_BIN)/python -m build
31
+
32
+ uninstall: $(VENV)
33
+ $(VENV_BIN)/python -m pip uninstall -y $(NAME)
34
+
35
+ documentation:
36
+ make html SPHINXBUILD="../$(VENV_BIN)/sphinx-build" -C docs/
37
+
38
+ test: install
39
+ $(VENV_BIN)/python -m pytest
40
+
41
+ coverage: install
42
+ $(VENV_BIN)/python -m pytest --cov=$(NAME) --cov-report=html:tests/htmlcov
43
+ open tests/htmlcov/index.html
44
+
45
+ upload: test documentation
46
+ $(VENV_BIN)/python -m pip install --upgrade twine
47
+ $(VENV_BIN)/python -m twine upload --verbose dist/*
48
+
49
+ download: uninstall
50
+ $(VENV_BIN)/python -m pip install $(NAME)
51
+
52
+ clean:
53
+ find . -type d -name '__pycache__' -print0 | xargs -0 rm -r || true
54
+ rm -rf dist docs/_build .pytest_cache .coverage tests/htmlcov
55
+
56
+ ########## Makefile end ##########
@@ -0,0 +1,153 @@
1
+ Metadata-Version: 2.4
2
+ Name: sqlchecker
3
+ Version: 0.3.1
4
+ Summary: This project analyses SQL statements and labels possible errors or complications.
5
+ Project-URL: Repository, https://github.com/DavidePonzini/sqlchecker
6
+ Project-URL: Documentation, https://sqlchecker.readthedocs.io/en/latest/index.html
7
+ Project-URL: Bug Tracker, https://github.com/DavidePonzini/sqlchecker/issues
8
+ Author-email: Davide Ponzini <davide.ponzini95@gmail.com>
9
+ License-File: LICENSE
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Programming Language :: Python :: 3
13
+ Requires-Python: >=3.11
14
+ Requires-Dist: psycopg2
15
+ Requires-Dist: python-dateutil
16
+ Requires-Dist: pyyaml
17
+ Requires-Dist: sqlerrors>=2.0.0
18
+ Requires-Dist: sqlglot
19
+ Requires-Dist: sqlparse
20
+ Requires-Dist: sqlscope>=1.0.16
21
+ Requires-Dist: z3-solver
22
+ Description-Content-Type: text/markdown
23
+
24
+ # Introduction
25
+ This project analyses SQL statements and labels possible errors or complications.
26
+
27
+ # Credits
28
+ Special thanks to Davide Miggiano and Flavio Venturini for their valuable contributions to the development of this project.
29
+
30
+ # Limitations
31
+ - Fully identified schema names are not supported when specifying column names (e.g. `SELECT schema.table.column [...]`)
32
+
33
+ # SQL Errors TODO List
34
+ ## Syntax Errors
35
+ | ID | Category | Name | Description | Base Query | Subquery | CTE |
36
+ | :---: | :-------: | :------------------------------------ | --------------------------------------------------------------------- | :--------: | :------: | :-: |
37
+ | 1 | SYN-1 | Ambiguous database object | Omitting correlation names | ✓ | | |
38
+ | 2 | SYN-1 | Ambiguous database object | Ambiguous column | ✓ | | |
39
+ | 3 | SYN-1 | Ambiguous database object | Ambiguous function | | | |
40
+ | 4 | SYN-2 | Undefined database object | Undefined column | ✓ | ✓ | ✓ |
41
+ | 5 | SYN-2 | Undefined database object | Undefined function | ✓ | ✓ | ✓ |
42
+ | 6 | SYN-2 | Undefined database object | Undefined parameter | ✓ | ✓ | ✓ |
43
+ | 7 | SYN-2 | Undefined database object | Undefined object | ✓ | ✓ | ✓ |
44
+ | 8 | SYN-2 | Undefined database object | Invalid schema name | ✓ | | |
45
+ | 9 | SYN-2 | Undefined database object | Misspellings | ✓ | | |
46
+ | 10 | SYN-2 | Undefined database object | Synonyms | | | |
47
+ | 11 | SYN-2 | Undefined database object | Omitting quotes around character data | ✓ | ✓ | ✓ |
48
+ | 12 | SYN-3 | Data type mismatch | Failure to specify column name twice | | | |
49
+ | 13 | SYN-3 | Data type mismatch | Data type mismatch | ✓ | | |
50
+ | 14 | SYN-4 | Illegal aggregate function placement | Using aggregate function outside SELECT or HAVING | ✓ | ✓ | ✓ |
51
+ | 15 | SYN-4 | Illegal aggregate function placement | Grouping error: aggregate functions cannot be nested | ✓ | ✓ | ✓ |
52
+ | 16 | SYN-5 | Illegal or insufficient grouping | Grouping error: extraneous or omitted grouping column | ✓ | ✓ | ✓ |
53
+ | 17 | SYN-5 | Illegal or insufficient grouping | Strange HAVING: HAVING without GROUP BY | ✓ | ✓ | ✓ |
54
+ | 18 | SYN-6 | Common syntax error | Confusing function with function | | | |
55
+ | 19 | SYN-6 | Common syntax error | Using WHERE twice | ✓ | ✓ | ✓ |
56
+ | 20 | SYN-6 | Common syntax error | Omitting the FROM clause | ✓ | ✓ | ✓ |
57
+ | 21 | SYN-6 | Common syntax error | Comparison with NULL | ✓ | ✓ | ✓ |
58
+ | 22 | SYN-6 | Common syntax error | Omitting the semicolon | ✓ | ✓ | ✓ |
59
+ | 23 | SYN-6 | Common syntax error | Date time field overflow | | | |
60
+ | 24 | SYN-6 | Common syntax error | Duplicate clause | | | |
61
+ | 25 | SYN-6 | Common syntax error | Using an undefined correlation name | | | |
62
+ | 26 | SYN-6 | Common syntax error | Too many columns in subquery | | | |
63
+ | 27 | SYN-6 | Common syntax error | Confusing table names with column names | | | |
64
+ | 28 | SYN-6 | Common syntax error | Restriction in SELECT clause (e.g., SELECT fee > 10) | ✓ | ✓ | ✓ |
65
+ | 29 | SYN-6 | Common syntax error | Projection in WHERE clause (e.g., WHERE firstname, surname) | ✓ | ✓ | ✓ |
66
+ | 30 | SYN-6 | Common syntax error | Confusing the order of keywords (e.g., FROM customer SELECT fee) | ✓ | | |
67
+ | 31 | SYN-6 | Common syntax error | Confusing the logic of keywords (e.g., grouping instead of ordering) | | | |
68
+ | 32 | SYN-6 | Common syntax error | Confusing the syntax of keywords (e.g., LIKE (‘A’, ‘B’)) | ✓ | ✓ | ✓ |
69
+ | 33 | SYN-6 | Common syntax error | Omitting commas | ✓ | ✓ | ✓ |
70
+ | 34 | SYN-6 | Common syntax error | Curly, square or unmatched brackets | ✓ | ✓ | ✓ |
71
+ | 35 | SYN-6 | Common syntax error | IS where not applicable | | | |
72
+ | 36 | SYN-6 | Common syntax error | Nonstandard keywords or standard keywords in wrong context | | | |
73
+ | 37 | SYN-6 | Common syntax error | Nonstandard operators (e.g., &&, \|\| or ==) | ✓ | ✓ | ✓ |
74
+ | 38 | SYN-6 | Common syntax error | Additional semicolon | ✓ | ✓ | ✓ |
75
+
76
+ ## Semantic Errors
77
+ | ID | Category | Name | Description | Base Query | Subquery | CTE |
78
+ | :---: | :-------: | :------------------------------------ | --------------------------------------------------------------------- | :--------: | :------: | :-: |
79
+ | 39 | SEM-1 | Inconsistent expression | AND instead of OR (empty result table) | ✓ | | |
80
+ | 40 | SEM-1 | Inconsistent expression | Implied, tautological or inconsistent expression | | | |
81
+ | 41 | SEM-1 | Inconsistent expression | DISTINCT in SUM or AVG | ✓ | ✓ | ✓ |
82
+ | 42 | SEM-1 | Inconsistent expression | DISTINCT that might remove important duplicates | | | |
83
+ | 43 | SEM-1 | Inconsistent expression | Wildcards without LIKE | ✓ | ✓ | ✓ |
84
+ | 44 | SEM-1 | Inconsistent expression | Incorrect wildcard: using _ instead of % or using, e.g., * | ✓ | ✓ | ✓ |
85
+ | 45 | SEM-1 | Inconsistent expression | Mixing a > 0 with IS NOT NULL or empty string with NULL | ✓ | ✓ | ✓ |
86
+ | 46 | SEM-2 | Inconsistent join | NULL in IN/ANY/ALL subquery | | | |
87
+ | 47 | SEM-2 | Inconsistent join | Join on incorrect column (matches impossible) | | | |
88
+ | 48 | SEM-3 | Missing join | Omitting a join | | | |
89
+ | 49 | SEM-4 | Duplicate rows | Many duplicates | | | |
90
+ | 50 | SEM-5 | Redundant column output | Constant column output | ✓ | | |
91
+ | 51 | SEM-5 | Redundant column output | Duplicate column output | ✓ | | |
92
+
93
+ ## Logical Errors
94
+ | ID | Category | Name | Description | Base Query | Subquery | CTE |
95
+ | :---: | :-------: | :------------------------------------ | --------------------------------------------------------------------- | :--------: | :------: | :-: |
96
+ | 52 | LOG-1 | Operator error | OR instead of AND | ✓ | ✓ | ✓ |
97
+ | 53 | LOG-1 | Operator error | Extraneous NOT operator | | | |
98
+ | 54 | LOG-1 | Operator error | Missing NOT operator | | | |
99
+ | 55 | LOG-1 | Operator error | Substituting existence negation with <> | | | |
100
+ | 56 | LOG-1 | Operator error | Putting NOT in front of incorrect IN/EXISTS | | | |
101
+ | 57 | LOG-1 | Operator error | Incorrect comparison operator or incorrect value compared | ✓ | ✓ | ✓ |
102
+ | 58 | LOG-2 | Join error | Join on incorrect table | | | |
103
+ | 59 | LOG-2 | Join error | Join when join needs to be omitted | | | |
104
+ | 60 | LOG-2 | Join error | Join on incorrect column (matches possible) | | | |
105
+ | 61 | LOG-2 | Join error | Join with incorrect comparison operator | | | |
106
+ | 62 | LOG-2 | Join error | Missing join | | | |
107
+ | 63 | LOG-3 | Nesting error | Improper nesting of expressions | | | |
108
+ | 64 | LOG-3 | Nesting error | Improper nesting of subqueries | | | |
109
+ | 65 | LOG-4 | Expression error | Extraneous quotes | | | |
110
+ | 66 | LOG-4 | Expression error | Missing expression | ✓ | ✓ | ✓ |
111
+ | 67 | LOG-4 | Expression error | Expression on incorrect column | ✓ | ✓ | ✓ |
112
+ | 68 | LOG-4 | Expression error | Extraneous expression | ✓ | ✓ | ✓ |
113
+ | 69 | LOG-4 | Expression error | Expression in incorrect clause | | | |
114
+ | 70 | LOG-5 | Projection error | Extraneous column in SELECT | ✓ | ✓ | ✓ |
115
+ | 71 | LOG-5 | Projection error | Missing column from SELECT | ✓ | ✓ | ✓ |
116
+ | 72 | LOG-5 | Projection error | Missing DISTINCT from SELECT | | | |
117
+ | 73 | LOG-5 | Projection error | Missing AS from SELECT | | | |
118
+ | 74 | LOG-5 | Projection error | Missing column from ORDER BY clause | ✓ | | |
119
+ | 75 | LOG-5 | Projection error | Incorrect column in ORDER BY clause | ✓ | | |
120
+ | 76 | LOG-5 | Projection error | Extraneous ORDER BY clause | ✓ | | |
121
+ | 77 | LOG-5 | Projection error | Incorrect ordering of rows | ✓ | | |
122
+ | 78 | LOG-6 | Function error | DISTINCT as function parameter where not applicable | | | |
123
+ | 79 | LOG-6 | Function error | Missing DISTINCT from function parameter | | | |
124
+ | 80 | LOG-6 | Function error | Incorrect function | | | |
125
+ | 81 | LOG-6 | Function error | Incorrect column as function parameter | | | |
126
+
127
+ # Complications
128
+ | ID | Category | Name | Description | Base Query | Subquery | CTE |
129
+ | :---: | :-------: | :------------------------------------ | --------------------------------------------------------------------- | :--------: | :------: | :-: |
130
+ | 82 | COM | Complication | Unnecessary complication | | | |
131
+ | 83 | COM | Complication | Unnecessary DISTINCT in SELECT clause | ✓ | ✓ | ✓ |
132
+ | 84 | COM | Complication | Unnecessary join | ✓ | | |
133
+ | 85 | COM | Complication | Unused correlation name | | | |
134
+ | 86 | COM | Complication | Correlation names are always identical | | | |
135
+ | 87 | COM | Complication | Unnecessarily general comparison operator | | | |
136
+ | 88 | COM | Complication | LIKE without wildcards | ✓ | ✓ | ✓ |
137
+ | 89 | COM | Complication | Unnecessarily complicated SELECT in EXISTS subquery | | | |
138
+ | 90 | COM | Complication | IN/EXISTS can be replaced by comparison | | | |
139
+ | 91 | COM | Complication | Unnecessary aggregate function | | | |
140
+ | 92 | COM | Complication | Unnecessary DISTINCT in aggregate function | | | |
141
+ | 93 | COM | Complication | Unnecessary argument of COUNT | | | |
142
+ | 94 | COM | Complication | Unnecessary GROUP BY in EXISTS subquery | | | |
143
+ | 95 | COM | Complication | GROUP BY with singleton groups | | | |
144
+ | 96 | COM | Complication | GROUP BY with only a single group | | | |
145
+ | 97 | COM | Complication | GROUP BY can be replaced with DISTINCT | | | |
146
+ | 98 | COM | Complication | UNION can be replaced by OR | | | |
147
+ | 99 | COM | Complication | Unnecessary column in ORDER BY clause | ✓ | | |
148
+ | 100 | COM | Complication | ORDER BY in subquery | | | |
149
+ | 101 | COM | Complication | Inefficient HAVING | | | |
150
+ | 102 | COM | Complication | Inefficient UNION | | | |
151
+ | 103 | COM | Complication | Condition in the subquery can be moved up | | | |
152
+ | 104 | COM | Complication | Condition on left table in LEFT OUTER JOIN | | | |
153
+ | 105 | COM | Complication | OUTER JOIN can be replaced by INNER JOIN | | | |
@@ -0,0 +1,130 @@
1
+ # Introduction
2
+ This project analyses SQL statements and labels possible errors or complications.
3
+
4
+ # Credits
5
+ Special thanks to Davide Miggiano and Flavio Venturini for their valuable contributions to the development of this project.
6
+
7
+ # Limitations
8
+ - Fully identified schema names are not supported when specifying column names (e.g. `SELECT schema.table.column [...]`)
9
+
10
+ # SQL Errors TODO List
11
+ ## Syntax Errors
12
+ | ID | Category | Name | Description | Base Query | Subquery | CTE |
13
+ | :---: | :-------: | :------------------------------------ | --------------------------------------------------------------------- | :--------: | :------: | :-: |
14
+ | 1 | SYN-1 | Ambiguous database object | Omitting correlation names | ✓ | | |
15
+ | 2 | SYN-1 | Ambiguous database object | Ambiguous column | ✓ | | |
16
+ | 3 | SYN-1 | Ambiguous database object | Ambiguous function | | | |
17
+ | 4 | SYN-2 | Undefined database object | Undefined column | ✓ | ✓ | ✓ |
18
+ | 5 | SYN-2 | Undefined database object | Undefined function | ✓ | ✓ | ✓ |
19
+ | 6 | SYN-2 | Undefined database object | Undefined parameter | ✓ | ✓ | ✓ |
20
+ | 7 | SYN-2 | Undefined database object | Undefined object | ✓ | ✓ | ✓ |
21
+ | 8 | SYN-2 | Undefined database object | Invalid schema name | ✓ | | |
22
+ | 9 | SYN-2 | Undefined database object | Misspellings | ✓ | | |
23
+ | 10 | SYN-2 | Undefined database object | Synonyms | | | |
24
+ | 11 | SYN-2 | Undefined database object | Omitting quotes around character data | ✓ | ✓ | ✓ |
25
+ | 12 | SYN-3 | Data type mismatch | Failure to specify column name twice | | | |
26
+ | 13 | SYN-3 | Data type mismatch | Data type mismatch | ✓ | | |
27
+ | 14 | SYN-4 | Illegal aggregate function placement | Using aggregate function outside SELECT or HAVING | ✓ | ✓ | ✓ |
28
+ | 15 | SYN-4 | Illegal aggregate function placement | Grouping error: aggregate functions cannot be nested | ✓ | ✓ | ✓ |
29
+ | 16 | SYN-5 | Illegal or insufficient grouping | Grouping error: extraneous or omitted grouping column | ✓ | ✓ | ✓ |
30
+ | 17 | SYN-5 | Illegal or insufficient grouping | Strange HAVING: HAVING without GROUP BY | ✓ | ✓ | ✓ |
31
+ | 18 | SYN-6 | Common syntax error | Confusing function with function | | | |
32
+ | 19 | SYN-6 | Common syntax error | Using WHERE twice | ✓ | ✓ | ✓ |
33
+ | 20 | SYN-6 | Common syntax error | Omitting the FROM clause | ✓ | ✓ | ✓ |
34
+ | 21 | SYN-6 | Common syntax error | Comparison with NULL | ✓ | ✓ | ✓ |
35
+ | 22 | SYN-6 | Common syntax error | Omitting the semicolon | ✓ | ✓ | ✓ |
36
+ | 23 | SYN-6 | Common syntax error | Date time field overflow | | | |
37
+ | 24 | SYN-6 | Common syntax error | Duplicate clause | | | |
38
+ | 25 | SYN-6 | Common syntax error | Using an undefined correlation name | | | |
39
+ | 26 | SYN-6 | Common syntax error | Too many columns in subquery | | | |
40
+ | 27 | SYN-6 | Common syntax error | Confusing table names with column names | | | |
41
+ | 28 | SYN-6 | Common syntax error | Restriction in SELECT clause (e.g., SELECT fee > 10) | ✓ | ✓ | ✓ |
42
+ | 29 | SYN-6 | Common syntax error | Projection in WHERE clause (e.g., WHERE firstname, surname) | ✓ | ✓ | ✓ |
43
+ | 30 | SYN-6 | Common syntax error | Confusing the order of keywords (e.g., FROM customer SELECT fee) | ✓ | | |
44
+ | 31 | SYN-6 | Common syntax error | Confusing the logic of keywords (e.g., grouping instead of ordering) | | | |
45
+ | 32 | SYN-6 | Common syntax error | Confusing the syntax of keywords (e.g., LIKE (‘A’, ‘B’)) | ✓ | ✓ | ✓ |
46
+ | 33 | SYN-6 | Common syntax error | Omitting commas | ✓ | ✓ | ✓ |
47
+ | 34 | SYN-6 | Common syntax error | Curly, square or unmatched brackets | ✓ | ✓ | ✓ |
48
+ | 35 | SYN-6 | Common syntax error | IS where not applicable | | | |
49
+ | 36 | SYN-6 | Common syntax error | Nonstandard keywords or standard keywords in wrong context | | | |
50
+ | 37 | SYN-6 | Common syntax error | Nonstandard operators (e.g., &&, \|\| or ==) | ✓ | ✓ | ✓ |
51
+ | 38 | SYN-6 | Common syntax error | Additional semicolon | ✓ | ✓ | ✓ |
52
+
53
+ ## Semantic Errors
54
+ | ID | Category | Name | Description | Base Query | Subquery | CTE |
55
+ | :---: | :-------: | :------------------------------------ | --------------------------------------------------------------------- | :--------: | :------: | :-: |
56
+ | 39 | SEM-1 | Inconsistent expression | AND instead of OR (empty result table) | ✓ | | |
57
+ | 40 | SEM-1 | Inconsistent expression | Implied, tautological or inconsistent expression | | | |
58
+ | 41 | SEM-1 | Inconsistent expression | DISTINCT in SUM or AVG | ✓ | ✓ | ✓ |
59
+ | 42 | SEM-1 | Inconsistent expression | DISTINCT that might remove important duplicates | | | |
60
+ | 43 | SEM-1 | Inconsistent expression | Wildcards without LIKE | ✓ | ✓ | ✓ |
61
+ | 44 | SEM-1 | Inconsistent expression | Incorrect wildcard: using _ instead of % or using, e.g., * | ✓ | ✓ | ✓ |
62
+ | 45 | SEM-1 | Inconsistent expression | Mixing a > 0 with IS NOT NULL or empty string with NULL | ✓ | ✓ | ✓ |
63
+ | 46 | SEM-2 | Inconsistent join | NULL in IN/ANY/ALL subquery | | | |
64
+ | 47 | SEM-2 | Inconsistent join | Join on incorrect column (matches impossible) | | | |
65
+ | 48 | SEM-3 | Missing join | Omitting a join | | | |
66
+ | 49 | SEM-4 | Duplicate rows | Many duplicates | | | |
67
+ | 50 | SEM-5 | Redundant column output | Constant column output | ✓ | | |
68
+ | 51 | SEM-5 | Redundant column output | Duplicate column output | ✓ | | |
69
+
70
+ ## Logical Errors
71
+ | ID | Category | Name | Description | Base Query | Subquery | CTE |
72
+ | :---: | :-------: | :------------------------------------ | --------------------------------------------------------------------- | :--------: | :------: | :-: |
73
+ | 52 | LOG-1 | Operator error | OR instead of AND | ✓ | ✓ | ✓ |
74
+ | 53 | LOG-1 | Operator error | Extraneous NOT operator | | | |
75
+ | 54 | LOG-1 | Operator error | Missing NOT operator | | | |
76
+ | 55 | LOG-1 | Operator error | Substituting existence negation with <> | | | |
77
+ | 56 | LOG-1 | Operator error | Putting NOT in front of incorrect IN/EXISTS | | | |
78
+ | 57 | LOG-1 | Operator error | Incorrect comparison operator or incorrect value compared | ✓ | ✓ | ✓ |
79
+ | 58 | LOG-2 | Join error | Join on incorrect table | | | |
80
+ | 59 | LOG-2 | Join error | Join when join needs to be omitted | | | |
81
+ | 60 | LOG-2 | Join error | Join on incorrect column (matches possible) | | | |
82
+ | 61 | LOG-2 | Join error | Join with incorrect comparison operator | | | |
83
+ | 62 | LOG-2 | Join error | Missing join | | | |
84
+ | 63 | LOG-3 | Nesting error | Improper nesting of expressions | | | |
85
+ | 64 | LOG-3 | Nesting error | Improper nesting of subqueries | | | |
86
+ | 65 | LOG-4 | Expression error | Extraneous quotes | | | |
87
+ | 66 | LOG-4 | Expression error | Missing expression | ✓ | ✓ | ✓ |
88
+ | 67 | LOG-4 | Expression error | Expression on incorrect column | ✓ | ✓ | ✓ |
89
+ | 68 | LOG-4 | Expression error | Extraneous expression | ✓ | ✓ | ✓ |
90
+ | 69 | LOG-4 | Expression error | Expression in incorrect clause | | | |
91
+ | 70 | LOG-5 | Projection error | Extraneous column in SELECT | ✓ | ✓ | ✓ |
92
+ | 71 | LOG-5 | Projection error | Missing column from SELECT | ✓ | ✓ | ✓ |
93
+ | 72 | LOG-5 | Projection error | Missing DISTINCT from SELECT | | | |
94
+ | 73 | LOG-5 | Projection error | Missing AS from SELECT | | | |
95
+ | 74 | LOG-5 | Projection error | Missing column from ORDER BY clause | ✓ | | |
96
+ | 75 | LOG-5 | Projection error | Incorrect column in ORDER BY clause | ✓ | | |
97
+ | 76 | LOG-5 | Projection error | Extraneous ORDER BY clause | ✓ | | |
98
+ | 77 | LOG-5 | Projection error | Incorrect ordering of rows | ✓ | | |
99
+ | 78 | LOG-6 | Function error | DISTINCT as function parameter where not applicable | | | |
100
+ | 79 | LOG-6 | Function error | Missing DISTINCT from function parameter | | | |
101
+ | 80 | LOG-6 | Function error | Incorrect function | | | |
102
+ | 81 | LOG-6 | Function error | Incorrect column as function parameter | | | |
103
+
104
+ # Complications
105
+ | ID | Category | Name | Description | Base Query | Subquery | CTE |
106
+ | :---: | :-------: | :------------------------------------ | --------------------------------------------------------------------- | :--------: | :------: | :-: |
107
+ | 82 | COM | Complication | Unnecessary complication | | | |
108
+ | 83 | COM | Complication | Unnecessary DISTINCT in SELECT clause | ✓ | ✓ | ✓ |
109
+ | 84 | COM | Complication | Unnecessary join | ✓ | | |
110
+ | 85 | COM | Complication | Unused correlation name | | | |
111
+ | 86 | COM | Complication | Correlation names are always identical | | | |
112
+ | 87 | COM | Complication | Unnecessarily general comparison operator | | | |
113
+ | 88 | COM | Complication | LIKE without wildcards | ✓ | ✓ | ✓ |
114
+ | 89 | COM | Complication | Unnecessarily complicated SELECT in EXISTS subquery | | | |
115
+ | 90 | COM | Complication | IN/EXISTS can be replaced by comparison | | | |
116
+ | 91 | COM | Complication | Unnecessary aggregate function | | | |
117
+ | 92 | COM | Complication | Unnecessary DISTINCT in aggregate function | | | |
118
+ | 93 | COM | Complication | Unnecessary argument of COUNT | | | |
119
+ | 94 | COM | Complication | Unnecessary GROUP BY in EXISTS subquery | | | |
120
+ | 95 | COM | Complication | GROUP BY with singleton groups | | | |
121
+ | 96 | COM | Complication | GROUP BY with only a single group | | | |
122
+ | 97 | COM | Complication | GROUP BY can be replaced with DISTINCT | | | |
123
+ | 98 | COM | Complication | UNION can be replaced by OR | | | |
124
+ | 99 | COM | Complication | Unnecessary column in ORDER BY clause | ✓ | | |
125
+ | 100 | COM | Complication | ORDER BY in subquery | | | |
126
+ | 101 | COM | Complication | Inefficient HAVING | | | |
127
+ | 102 | COM | Complication | Inefficient UNION | | | |
128
+ | 103 | COM | Complication | Condition in the subquery can be moved up | | | |
129
+ | 104 | COM | Complication | Condition on left table in LEFT OUTER JOIN | | | |
130
+ | 105 | COM | Complication | OUTER JOIN can be replaced by INNER JOIN | | | |