Skip to content

sukhoy94/sql-anon

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

SQL Anonymizer (PostgreSQL)

A simple Python script that anonymizes PostgreSQL SQL queries by replacing table names, column names and function names while preserving query structure.

Designed to safely share SQL queries with LLMs without leaking schema details.


Features

  • Anonymizes:
    • table names
    • column names
    • function names
  • Preserves SQL keywords and structure
  • Context-aware (distinguishes tables vs columns in UPDATE / SET / WHERE)
  • Works with multi-statement SQL files
  • PostgreSQL-oriented

Requirements

  • Python 3.8+
  • sqlparse

Install dependency:

pip install sqlparse

Usage

  1. Put your SQL query (or queries) into input.txt

  2. Run the script:

python anonymize_sql.py
  1. The anonymized SQL will be written to output.txt

Example

Input (input.txt)

UPDATE users
SET status = 'ready'
WHERE user_id = 1;

Output (output.txt)

UPDATE table_1
SET column_1 = 'ready'
WHERE column_2 = 1;

Notes

  • SQL keywords are preserved
  • String and numeric literals are not anonymized
  • The same identifier is always replaced with the same anonymized name
  • Intended for analysis, debugging and LLM usage --- not for execution

Limitations

  • Uses heuristics (not a full SQL AST)
  • Limited support for advanced PostgreSQL features (e.g. JSONB operators)
  • Not suitable for dynamic SQL

License

MIT

About

Python script that anonymizes PostgreSQL SQL queries by replacing table names, column names and function names while preserving query structure

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages