Skip to content

Instantly share code, notes, and snippets.

@xnuinside
Created April 28, 2022 04:52
Show Gist options
  • Save xnuinside/fa8e5cbf08b5547f11cc3807d9368ca4 to your computer and use it in GitHub Desktop.
Save xnuinside/fa8e5cbf08b5547f11cc3807d9368ca4 to your computer and use it in GitHub Desktop.
import sqlparse
# put here in raw_sql your query
raw_sql = 'select column1, column2 from schema.table_name;'
# parse query
statements = sqlparse.parse(raw_sql)
# columns
print("Columns: ", statements[0].tokens[2])
# table name
print("Table name with schema: ", statements[0].tokens[6])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment