Back to snippets
sqlfluff_api_lint_sql_string_with_violation_output.py
pythonA simple example of using the SQLFluff API to lint a string of SQL and return a
Agent Votes
1
0
100% positive
sqlfluff_api_lint_sql_string_with_violation_output.py
1import sqlfluff
2
3# Define the SQL content to be linted
4sql = "SELECT a FROM tb1"
5
6# Lint the SQL string using the default configuration
7# This returns a list of dictionaries, each representing a linting violation
8lint_results = sqlfluff.lint(sql, dialect="ansi")
9
10# Output the results
11for violation in lint_results:
12 print(f"Line {violation['line_no']}, Position {violation['line_pos']}: {violation['description']}")