NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
PyPI · #2013 most downloaded on PyPI
Uses sqlglot to parse SQL queries and extract metadata
Last release 3 months ago
30 Jun 2026
Ships fairly regularly
a new release about every 2 months
Nearly every release is documented
notes for 41 of 44 stable releases
Nothing withdrawn
no release was ever pulled
9 years old
44 releases · first in 2018
Bump dependabot/fetch-metadata from 2.5.0 to 3.1.0 by @dependabot[bot] in https://github.com/macbre/sql-metadata/pull/619
Full Changelog: https://github.com/macbre/sql-metadata/compare/v3.0.0...v3.0.1
One column per quarter.
Bump coverage from 7.10.7 to 7.13.4 by @dependabot[bot] in https://github.com/macbre/sql-metadata/pull/610
Full Changelog: https://github.com/macbre/sql-metadata/compare/v2.20.0...v3.0.0
Bump actions/cache from 4 to 5 by @dependabot[bot] in https://github.com/macbre/sql-metadata/pull/600
Parser.columns drops column named source when it is the last column in a SELECT statement by @macbre in https://github.com/macbre/sql-metadata/pull/603Parser.with_names for malformed WITH statements by @macbre in https://github.com/macbre/sql-metadata/pull/605AGENTS.md documentation for developers and AI agents by @macbre in https://github.com/macbre/sql-metadata/pull/606Full Changelog: https://github.com/macbre/sql-metadata/compare/v2.19.0...v2.20.0
Bump black from 25.9.0 to 25.11.0 by @dependabot[bot] in https://github.com/macbre/sql-metadata/pull/595
Full Changelog: https://github.com/macbre/sql-metadata/compare/v2.18.0...v2.19.0
Bump pylint from 3.3.6 to 3.3.7 by @dependabot[bot] in https://github.com/macbre/sql-metadata/pull/554
Full Changelog: https://github.com/macbre/sql-metadata/compare/v2.17.0...v2.18.0
Bump black from 24.10.0 to 25.1.0 by @dependabot in https://github.com/macbre/sql-metadata/pull/548
ALTER TABLE ... ADD KEY queries by @macbre in https://github.com/macbre/sql-metadata/pull/553Full Changelog: https://github.com/macbre/sql-metadata/compare/v2.16.0...v2.17.0
Bump pytest from 8.3.3 to 8.3.4 by @dependabot in https://github.com/macbre/sql-metadata/pull/533
Full Changelog: https://github.com/macbre/sql-metadata/compare/v2.15.0...v2.16.0
Bump sqlparse from 0.5.1 to 0.5.2 by @dependabot in https://github.com/macbre/sql-metadata/pull/531
Full Changelog: https://github.com/macbre/sql-metadata/compare/v2.14.0...v2.15.0
Bump pylint from 3.2.6 to 3.2.7 by @dependabot in https://github.com/macbre/sql-metadata/pull/524
Full Changelog: https://github.com/macbre/sql-metadata/compare/v2.13.0...v2.14.0
Support for the TRUNCATE TABLE query parsing by @T-Santos in https://github.com/macbre/sql-metadata/pull/521
TRUNCATE TABLE query parsing by @T-Santos in https://github.com/macbre/sql-metadata/pull/521is_alias_without_as logical error by @MiuNice in https://github.com/macbre/sql-metadata/pull/523Full Changelog: https://github.com/macbre/sql-metadata/compare/v2.12.0...v2.13.0
build(deps-dev): bump black from 24.4.0 to 24.4.1 by @dependabot in https://github.com/macbre/sql-metadata/pull/483
Full Changelog: https://github.com/macbre/sql-metadata/compare/v2.11.0...v2.12.0
ClickHouse: improved tokens handling by @darkydash in https://github.com/macbre/sql-metadata/pull/450
Full Changelog: https://github.com/macbre/sql-metadata/compare/v2.10.0...v2.11.0
Fix #377 #390 #394 by @Byunk in https://github.com/macbre/sql-metadata/pull/440
Full Changelog: https://github.com/macbre/sql-metadata/compare/v2.9.0...v2.10.0
Parser.tokens: ignore flake8 error by @macbre in https://github.com/macbre/sql-metadata/pull/425
Thanks!
Full Changelog: https://github.com/macbre/sql-metadata/compare/v2.8.0...v2.9.0
Fix handling of LIMIT / OFFSET in queries with the IN condition by @macbre in https://github.com/macbre/sql-metadata/pull/387
Full Changelog: https://github.com/macbre/sql-metadata/compare/v2.7.0...v2.8.0
build(deps-dev): bump black from 22.3.0 to 22.6.0 by @dependabot in https://github.com/macbre/sql-metadata/pull/325
Full Changelog: https://github.com/macbre/sql-metadata/compare/v2.6.0...v2.7.0
build(deps-dev): bump pylint from 2.13.7 to 2.13.8 by @dependabot in https://github.com/macbre/sql-metadata/pull/315
Full Changelog: https://github.com/macbre/sql-metadata/compare/v2.5.0...v2.6.0
build(deps): bump actions/cache from 2 to 3 by @dependabot in https://github.com/macbre/sql-metadata/pull/299
AS ( from window clause as query start by @vakhmenin in https://github.com/macbre/sql-metadata/pull/310Full Changelog: https://github.com/macbre/sql-metadata/compare/v2.4.0...v2.5.0
build(deps-dev): bump pylint from 2.10.2 to 2.11.1 by @dependabot in https://github.com/macbre/sql-metadata/pull/237
USING to column keywords by @glentakahashi in https://github.com/macbre/sql-metadata/pull/255Hi and thanks, folks!
Full Changelog: https://github.com/macbre/sql-metadata/compare/v2.3.0...v2.4.0
Welcome, @christopherpickering, as our new contributor 🙂
internals - Multi from aliases (by @collerek)bug - Query including Distinct not workingdependencies - build(deps-dev): bump black from 21.6b0 to 21.7b0 (by @dependabot[bot])internals - CI - install the latest black versiondependencies - build(deps-dev): bump pylint from 2.9.3 to 2.9.4 (by @dependabot[bot])dependencies - build(deps-dev): bump coveralls from 3.1.0 to 3.2.0 (by @dependabot[bot])pr - Fix for Casting values results in incorrect alias reporting (by @collerek)dependencies - build(deps-dev): bump pylint from 2.9.5 to 2.9.6 (by @dependabot[bot])pr - Ignore case on column alias names from subquery (by @christopherpickering)internals - snok/install-poetry - use a default Poetry versiondependencies - build(deps-dev): bump pylint from 2.9.6 to 2.10.2 (by @dependabot[bot])internals - Extract conditions (by @collerek)dependencies - build(deps-dev): bump black from 21.7b0 to 21.8b0 (by @dependabot[bot])dependencies - build(deps-dev): bump pytest from 6.2.4 to 6.2.5 (by @dependabot[bot])pr - Restore fully qualified columns (by @collerek)pr - fix recurrent aliases names leading to infinite loop (by @collerek)pr - allow redundant parentheses around (sub)queries (by @collerek)pr - additional test for cast (by @collerek)dependencies - build(deps): bump sqlparse from 0.4.1 to 0.4.2 (by @dependabot[bot])Welcome, @christopherpickering, as our new contributor 🙂
This release of sql-metadata brings even further improvement of handling of with and table creation statements. We also keep up to date with our depen
This release of sql-metadata brings even further improvement of handling of with and table creation statements. We also keep up to date with our dependencies and improving CI pipeline.
build(deps-dev): bump black from 21.5b2 to 21.6b0 #167 Fix create schema #171 Create table with schema detects field names as tables #168 Fix for nested with statements in select #173 CI - install Poetry 1.1.7 #174 build(deps-dev): bump pylint from 2.8.3 to 2.9.0 #178 nested with statement causes confusion #172 build(deps-dev): bump pylint from 2.9.0 to 2.9.1 #179 build(deps-dev): bump pylint from 2.9.1 to 2.9.3 #180
This minor release brings two fixes:
This minor release brings two fixes:
bug - Fix parsing with clauses, fix for #161 (by @collerek)bug - Handle leading comments in queries (by @macbre)This release of sql-metadata brings improved handling of subqueries (thanks #154) and of `CREATE TABLE` queries containing a `WITH` clause (#157).
This release of sql-metadata brings improved handling of subqueries (thanks #154) and of CREATE TABLE queries containing a WITH clause (#157).
As an internal change improving our development Coveralls has been introduced that tracks code coverage of this project (#159).
As always we're staying up to date with various dependencies.
dependencies - build(deps-dev): bump pylint from 2.8.2 to 2.8.3 (by @dependabot[bot])dependencies - build(deps-dev): bump black from 21.5b1 to 21.5b2 (by @dependabot[bot])dependencies - Update black to 21.5b2enhancement - Resolving subqueries columns (by @collerek)bug - The tables property is still having difficulties finding the tables in a CTAS (by @tipanverella)dependencies - build(deps-dev): bump pytest-cov from 2.12.0 to 2.12.1 (by @dependabot[bot])bug - Fix for create table with with clause (by @collerek)internals - Automerge dependabot pull requestsinternals - Upload coverage report to CoverallsThis release of sql-metadata brings a few fixes regarding handling of leading digits in table names (#139), inline comments (#147) and columns with na
This release of sql-metadata brings a few fixes regarding handling of leading digits in table names (#139), inline comments (#147) and columns with names containing SQL keywords (#141).
bug - Tables with leading digits are not properly recognizedenhancement - Improved handling of tables names with leading digitsbug - Columns with names that start with a keyword are not recognized as a column (by @markderry)dependencies - build(deps-dev): bump pytest-cov from 2.11.1 to 2.12.0 (by @dependabot[bot])enhancement - Tables with leading digits (by @collerek)bug - Relevant keywords change, fix parenthesis helper (by @collerek)bug - Queries with in-line comments (--) are commenting out the entire rest of the query (by @taringoo)internals - CI - update poetry action versionThis major release of sql-metadata brings a completely new parser and API implemented by @collerek on top of proposals from #83 and #98.
This major release of sql-metadata brings a completely new parser and API implemented by @collerek on top of proposals from #83 and #98.
The gist of the changes is the introduction of the Parser class (see #121) that is later used to get the list columns, tables, aliases.
CREATE TABLE queries are now supported (#35). Aliases handling has been greatly improved thanks to #131.
Code coverage has been improved and is now kept at 100%.
from sql_metadata import Parser
parsed = Parser("SELECT test, id FROM foo, bar")
parsed.columns # ['test', 'id']
parsed.tables # ['foo', 'bar']
sql_metadata 1.xsql_metadata.compat module has been implemented to make the introduction of sql-metadata v2.0 smoother.
You can use it by simply changing the imports in your code from:
from sql_metadata import get_query_columns, get_query_tables
into:
from sql_metadata.compat import get_query_columns, get_query_tables
The following functions from the old API are available in the sql_metadata.compat module:
generalize_sqlget_query_columns (since #131 columns aliases ARE NOT returned by this function)get_query_limit_and_offsetget_query_tablesget_query_tokenspreprocess_queryenhancement - Support for CREATE TABLE... statements (by @sandeep-pareek)enhancement - New API [draft]Postgres - Support Postgres quoted identifiers (by @LanDinh)internals - Improve get_query_tokens iteratorquestion - Best way to get an array of values? (by @jplock)bug - missing tables returned by sql_metadata.get_query_tables (by @tdebroc)enhancement - New parser, bug fixes and new functionality. (by @collerek)bug - sql_metadata.get_query_columns result error (by @chen-ABC)enhancement - Add a support for CREATE TABLE queriespr - Improved handling of custom SQL functions when getting the list of columnsbug - get_query_tables() is returning columns on WITH statements (by @remisalmon)dependencies - build(deps-dev): bump black from 21.4b2 to 21.5b0 (by @dependabot[bot])dependencies - build(deps-dev): bump pytest from 6.2.3 to 6.2.4 (by @dependabot[bot])enhancement - Column aliases support (by @collerek)dependencies - build(deps-dev): bump black from 21.5b0 to 21.5b1 (by @dependabot[bot])internals - tool.coverage.report: require 100% code coverageinternals - CI - use Makefile commandsinternals - Introduce a compatibility layer for 1.x functions* #100 internals - Lint after running tests * #101 dependencies - build(deps-dev): bump pylint from 2.6.2 to 2.7.0 (by @dependabot[bot]) * #102 depend
internals - Lint after running testsdependencies - build(deps-dev): bump pylint from 2.6.2 to 2.7.0 (by @dependabot[bot])dependencies - build(deps-dev): bump pylint from 2.7.0 to 2.7.1 (by @dependabot[bot])dependencies - build(deps-dev): bump coverage from 5.4 to 5.5 (by @dependabot[bot])internals - Use poetry 1.1.5internals - CI - store ~/.cache dir + pip install wheelinternals - actions/cache: invalidate on poetry.lock changeenhancement - Improved brackets handlingdependencies - build(deps-dev): bump pytest from 6.2.2 to 6.2.3 (by @dependabot[bot])dependencies - snok/install-poetry@v1.1.3dependencies - build(deps-dev): bump pylint from 2.7.4 to 2.8.1 (by @dependabot[bot])dependencies - build(deps-dev): bump pylint from 2.8.1 to 2.8.2 (by @dependabot[bot])dependencies - Upgrade black to 21.4b1dependencies - build(deps-dev): bump black from 21.4b1 to 21.4b2 (by @dependabot[bot])This release brings two bug fixes from @aborecki (dzięki! 🙂 🇵🇱 ) and introduces `poetry` as the dependency manager.
This release brings two bug fixes from @aborecki (dzięki! 🙂 🇵🇱 ) and introduces poetry as the dependency manager.
bug - Wrong parsing results from get_query_tables for select with UNION (by @aborecki)bug - Wrong parsing results get_query_tables for spaces in GROUP BY keyword (by @aborecki)internals - Use Poetry as dependency manager and PyPI publish tooldependencies - build(deps-dev): bump pytest from 6.2.1 to 6.2.2 (by @dependabot[bot])dependencies - build(deps-dev): bump coverage from 5.3.1 to 5.4 (by @dependabot[bot])internals - Run tests on both Python 3.8 and 3.9internals - Test with Python 3.7 toointernals - Improve CI cache handlinginternals - Load cached Poetry venvinternals - Try to test using Python 3.6 and 3.7 toointernals - Tests - add code coverage reportbug - Union's don't return the correct result (by @dylwylie)dependencies - build(deps-dev): bump pylint from 2.6.0 to 2.6.2 (by @dependabot[bot])pr - Extend test coverage for UNION queriesget_query_columns does not return nothing if parsing SELECT DISTINCT #72 (reported by @benzzdan) get_query_tables() CTE Case Sensitive for SELECT #71
get_query_columns does not return nothing if parsing SELECT DISTINCT #72 (reported by @benzzdan) get_query_tables() CTE Case Sensitive for SELECT #71 (reported by @nehalj12)
Install black code formatter #63 build(deps-dev): bump coverage from 5.3 to 5.3.1 #75 build(deps-dev): bump pytest from 6.2.0 to 6.2.1 #74 build(deps-dev): bump pytest from 6.1.2 to 6.2.0 #73 CI: cache pip dependencies #70 build(deps-dev): bump pytest from 6.1.1 to 6.1.2 #69
sqlparse - Remove debug print statement
sqlparse - Remove debug print statement (https://github.com/andialbrecht/sqlparse/commit/ab53a4b25f853a79d63a6723efaf568b0be02711)
Bump pytest from 6.0.1 to 6.0.2 #62
get_query_tables doesn't respect table names with dashes in their name #60* #38 bug - Ignoring Multiple FROM tables when they prefixed by DATASET (reported by @rubensmussicury) * #52 bug - Incorrect column names when table a
bug - Ignoring Multiple FROM tables when they prefixed by DATASET (reported by @rubensmussicury)bug - Incorrect column names when table aliases are used (reported by @akku1506 and fixed in #58)dependencies - Bump coverage from 5.2 to 5.2.1 (by @dependabot[bot])dependencies - Bump pytest from 5.4.3 to 6.0.0 (by @dependabot[bot])dependencies - Bump pytest from 6.0.0 to 6.0.1 (by @dependabot[bot])`sql SELECT s.cust_id,count(s.cust_id) FROM SH.sales s GROUP BY s.cust_id `
SELECT s.cust_id,count(s.cust_id) FROM SH.sales s GROUP BY s.cust_id
This query was giving s.cust_id as a table name instead of SH.sales. This is now fixed by #54.
automated PyPI publish on new release creation
get_query_tables: Add support for database.schema.table notation (thanks to @dylanhogg)The following bugs were solved by updating sqlparse dependency in #40:
The following bugs were solved by updating sqlparse dependency in #40:
* #29 - get_query_tables: fix handling of "SELECT x ORDER BY y" queries * use Semantic Versioning
* #25 - Handle CAST() and CONVERT() functions * #27 - Handle Apache Hive queries
CAST() and CONVERT() functions#17 - Add support for table schemas in get_query_tables()
#17 - Add support for table schemas in get_query_tables()
* #13 - get_query_columns: add support for INSERT queries * #12 - handle empty query argument of get_query_tokens * #19 - update dependencies * #18 -
get_query_columns: add support for INSERT queriesget_query_tokens get_query_tables() breaks on INSERT INTO ... SELECTnormalize_sql to sql-metadataNothing published for this version
Nothing published for this version
* #10 - Introduce get_query_limit_and_offset()
get_query_limit_and_offset()* #6 - Handle more complex SQL queries
* #4 - Handle more queries and add tests from `query-digest`
query-digestNothing published for this version
Your coding agent can read these notes before it upgrades. Set up the MCP server →