Ruby extension to parse, deparse and normalize SQL queries using the PostgreSQL query parser

This Ruby extension uses the actual PostgreSQL server source to parse SQL queries and return the internal PostgreSQL parsetree.In addition the extension allows you to normalize queries (replacing constant values with ?) and parse these normalized queries into a parsetree again.When you build this extension, it builds parts of the PostgreSQL server source (see libpg_query), and then statically links it into this extension.This is slightly crazy, but is the only reliable way of parsing all valid PostgreSQL queries.You can find further examples and a longer rationale here: https://pganalyze.com/blog/parse-postgresql-queries-in-ruby.html.
Ruby extension to parse, deparse and normalize SQL queries using the PostgreSQL query parser #ruby #rubydeveloper #rubyonrails #sql https://www.rubyonrails.ba/single/ruby-extension-to-parse-deparse-and-normalize-sql-queries-using-the-postgresql-query-parser

Nezir Zahirovic

Contractor Ruby On Rails (8+ years) / MCPD .Net / C# / Asp.Net / CSS / SQL / (11 years)

related articles