Skip to content

Instantly share code, notes, and snippets.

View jgysland's full-sized avatar

Jake Gysland jgysland

  • Minneapolis, Minnesota
View GitHub Profile
@jgysland
jgysland / table_re.py
Created March 15, 2016 15:22
regular expression pattern to find table names in most PostgreSQL(-like) queries
import re
# this pattern should pick out tablenames or schema.tablenames in
# most contexts, respecting legal names, including double-quoted table names
# with otherwise illegal characters.
# known exceptions include GRANT statements and "joins" using multiple tables
# in FROM with WHERE conditions.
pattern = r'(?:from|join|(?:create|alter|drop|truncate|update)' \
'(?:\s*table|\s*view|\s*)(?:\sas)?)(?:\s+)' \