opyeb sqlmask

Anonymising SQL dumps — INSERT, UPDATE and COPY without breaking them

2026-11-29 · 2 min read

Keep the statement, change the values. That is what makes the output loadable again.

The short answer

Change the value literals in INSERT, UPDATE, VALUES and COPY; leave identifiers, comments and structure alone. WHERE is untouched by default.

INSERT — the column list is the map

In INSERT INTO table (columns…) VALUES (values…), (values…) the column list tells the tool which value is which. Without a column list the positions are named c1, c2 and only pattern detection applies.

String values are rewritten inside their single quotes and re-quoted, doubling any quote that appears in the value.

UPDATE — SET only, WHERE optional

Only the values assigned in the SET clause change. WHERE literals stay as they are, so the transformed statement still targets the same rows.

Enable the WHERE option if you want those literals changed too. The condition may then match different rows, so for fixture generation it is usually unnecessary.

COPY — the tab-separated block

The tab-separated rows after PostgreSQL COPY … FROM stdin are processed as well, using the COPY column list or c1, c2 when there is none.

\N is treated as NULL and left alone; \t, \n and \\ escapes are unescaped for detection and escaped again on output.

Numeric literals and quoting

If a value is an unquoted number (card_no = 4111111111111111) and the masked value contains an asterisk, it is quoted as a string. That changes the type for a numeric column, so watch the warning in the stats.

In full-redaction mode numeric literals become 0 to keep their type.

What is left alone

These are deliberately untouched. Review them before sharing.

Example

Paste this and only the SET values change; the 42 in WHERE stays.

UPDATE customers
   SET email = 'user02@example.invalid',
       phone = '010-0000-0002'
 WHERE customer_id = 42;

Questions

What happens with an INSERT without a column list?

Values are named c1, c2 and only value patterns apply. Use a column list if you want column-name rules.

Does ON CONFLICT or RETURNING break it?

Only the VALUES part is processed; later clauses are left alone and the ON CONFLICT column list is not mistaken for values.

Can a file hold several statements?

Yes. Statements are split on semicolons and any statement that is not INSERT, UPDATE, VALUES or COPY is counted and skipped.

Sources

Every example here can be pasted into the workbench as it is.

Open the workbench