sqlparse VS pg_query

Compare sqlparse vs pg_query and see what are their differences.

sqlparse

A non-validating SQL parser module for Python (by andialbrecht)

pg_query

Ruby extension to parse, deparse and normalize SQL queries using the PostgreSQL query parser (by pganalyze)
Our great sponsors
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • WorkOS - The modern identity platform for B2B SaaS
  • SaaSHub - Software Alternatives and Reviews
sqlparse pg_query
7 1
3,581 752
- 1.5%
8.2 6.3
5 days ago about 2 months ago
Python C
BSD 3-clause "New" or "Revised" License BSD 3-clause "New" or "Revised" License
The number of mentions indicates the total number of mentions that we've tracked plus the number of user suggested alternatives.
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.

sqlparse

Posts with mentions or reviews of sqlparse. We have used some of these posts to build our list of alternatives and similar projects. The last one was on 2023-06-08.
  • Show HN: Databasediagram.com – Private, Text to Entity-Relationship Diagram Tool
    7 projects | news.ycombinator.com | 8 Jun 2023
    Suggest checking out the sqlparse library for a way to do the different flavours without needing to address each case directly: https://github.com/andialbrecht/sqlparse
  • Data Load Diagram
    2 projects | /r/dataengineering | 6 Mar 2023
    Gotcha, since we haven't actually written all of this yet I don't have any useful code snippets to share but we've discussed tackling the problem internally using something like sqlparse. You'd need to identify the relevant sql chunks, parse them for table dependency information and then create the relevant entities in whichever data lineage tool you were using.
  • This Week In Python
    5 projects | dev.to | 16 Sep 2022
    sqlparse – A non-validating SQL parser module for Python
  • Open Source SQL Parsers
    17 projects | dev.to | 8 Oct 2021
    Regular expressions is a popular approach to extract information from SQL statements. However, regular expressions quickly become too complex to handle common features like WITH, sub-queries, windows clauses, aliases and quotes. sqlparse is a popular python package that uses regular expressions to parse SQL.
  • Automated SQL formatting checks
    2 projects | /r/dataengineering | 27 Sep 2021
    This one is not bad: https://github.com/andialbrecht/sqlparse.
  • Let's write a compiler, part 5: A code generator
    14 projects | news.ycombinator.com | 19 Aug 2021
  • BigQuery Lineage
    1 project | /r/bigquery | 7 May 2021
    We used this repo for this: https://github.com/andialbrecht/sqlparse. I may have miscommunicated. We didn't write the parser from scratch, we created a way for the parser to detect downstream and upstream dependencies of the resource.

pg_query

Posts with mentions or reviews of pg_query. We have used some of these posts to build our list of alternatives and similar projects. The last one was on 2021-10-08.

What are some alternatives?

When comparing sqlparse and pg_query you can also consider the following projects:

zetasql - ZetaSQL - Analyzer Framework for SQL

mo-sql-parsing - Let's make a SQL parser so we can provide a familiar interface to non-sql datastores!

pyparsing - Python library for creating PEG parsers [Moved to: https://github.com/pyparsing/pyparsing]

pg_query_go - Go library to parse and normalize SQL queries using the PostgreSQL query parser

Lark - Lark is a parsing toolkit for Python, built with a focus on ergonomics, performance and modularity.

libpg_query - C library for accessing the PostgreSQL parser outside of the server environment

PLY - Python Lex-Yacc

parser - A MySQL Compatible SQL Parser

sqlfluff - A modular SQL linter and auto-formatter with support for multiple dialects and templated code.

pglast - PostgreSQL Languages AST and statements prettifier: master branch covers PG10, v2 branch covers PG12, v3 covers PG13, v4 covers PG14, v5 covers PG15, v6 covers PG16

Pygments

pg_parse - PostgreSQL parser for Rust that uses the actual PostgreSQL server source to parse SQL queries and return the internal PostgreSQL parse tree.