Skip to main content

Extract table names and other information from SQL queries

Project description

PySqlParse

Find table names and other information in a SQL query

Installation

pip3 install pysqlparse

Use

Import

from pysqlparse import parser
...

get_table_names

Returns a set of all table names (without aliases) found in the SQL string.

from pysqlparse import parser
print(parser.get_table_names('''
        SELECT *
            FROM requests.by_account m
            INNER JOIN customer_data.styles s ON m.version = s.id
            LEFT JOIN profiles.users u ON m.csm = u.id
      '''))

Returns:

{'request.by_account', 'customer_data.styles', 'profiles.users'}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pysqlparse-0.0.2.tar.gz (5.7 kB view hashes)

Uploaded Source

Built Distribution

pysqlparse-0.0.2-py3-none-any.whl (6.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page