Skip to content

Expose pg_query_normalize() as normalize() - #244

Merged
lelit merged 4 commits into
lelit:v8from
R3gardless:expose-normalize
Oct 29, 2026
Merged

lelit merged 4 commits into
lelit:v8from
R3gardless:expose-normalize

Conversation

@R3gardless

Copy link
Copy Markdown
Contributor

As discussed in #242, this adds pglast.parser.normalize(), also exported from pglast like fingerprint():

>>> normalize("SELECT * FROM x WHERE y = 'foo' AND z = 42")
'SELECT * FROM x WHERE y = $1 AND z = $2'

With utility_only=True it calls pg_query_normalize_utility() instead, which only touches utility statements, e.g. the password in CREATE ROLE.

pgpp gets a -P/--parametrize option that prints the result of normalize().

The regenerated parser.c is in a separate commit. Once #241 is in, I'll add normalize() to the memory leak tests as well.

It replaces the constants in a statement with $n parameters, as pg_stat_statements
does. With utility_only=True it uses pg_query_normalize_utility() instead, which only
touches utility statements.
@R3gardless

Copy link
Copy Markdown
Contributor Author

Now that #241 is in, I rebased this on v8 and added normalize() to the memory leak tests. I also added it to __all__, which I had missed.

@lelit
lelit merged commit 85d6276 into lelit:v8 Oct 29, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants