Skip to content

mask

mask replaces entity characters with a masking character. Use it for partial redaction when you need to hide selected characters while preserving useful structure such as length, separators, or visible prefixes.

ParameterTypeDefaultDescription
masking_charSTRING (1 char)"*"Character used for masking.
chars_to_maskINTnullHow many characters to mask. null (omitted) = mask all; 0 = mask none; positive N = mask N characters.
from_endBOOLEANtrueWhen chars_to_mask is set, count from the end of the value. Set false to count from the start.
mask_all_charsBOOLEANfalseWhen false, only alphanumeric characters are masked (separators like - and spaces are preserved). When true, every character position is masked, including separators.
SELECT app_public.mask(
'SSN: 078-05-1120, Card: 4532-7891-2345-6672',
OBJECT_CONSTRUCT(
'entity_config', OBJECT_CONSTRUCT(
'US_SSN', OBJECT_CONSTRUCT('operator', 'mask'),
'CREDIT_CARD', OBJECT_CONSTRUCT(
'operator', 'mask',
'operator_params', OBJECT_CONSTRUCT('masking_char', 'X')
)
)
)
);
-- SSN: ***-**-****, Card: XXXX-XXXX-XXXX-XXXX

Use this when a workflow needs to hide the trailing digits while leaving the rest of the value visible:

SELECT app_public.mask(
'Phone: 415-555-0100',
OBJECT_CONSTRUCT(
'entity_config', OBJECT_CONSTRUCT(
'PHONE_NUMBER', OBJECT_CONSTRUCT(
'operator', 'mask',
'operator_params', OBJECT_CONSTRUCT(
'masking_char', 'X',
'chars_to_mask', 4,
'from_end', TRUE
)
)
)
)
);
-- Phone: 415-555-XXXX

Example — mask_all_chars for uniform output

Section titled “Example — mask_all_chars for uniform output”

Mask every position, including separators. This hides punctuation and spacing, but the output still preserves entity length:

SELECT app_public.mask(
'SSN: 078-05-1120',
OBJECT_CONSTRUCT(
'entity_config', OBJECT_CONSTRUCT(
'US_SSN', OBJECT_CONSTRUCT(
'operator', 'mask',
'operator_params', OBJECT_CONSTRUCT('mask_all_chars', TRUE)
)
)
)
);
-- SSN: ***********
  • Workflows that require masking specific portions of credit card numbers, phone numbers, or other structured identifiers.
  • Partial redaction where reviewers need to see length or format while selected characters are hidden.
  • When downstream workflows do not need stable replacement values for joins or grouping.
  • masking_char must be exactly 1 character.
  • When chars_to_mask > len(entity), the entire entity is masked.
  • Masked output preserves original length — ***-**-**** is the same length as 078-05-1120.
  • Partial masking can leave unmasked characters, length, and format visible. Use a stricter operator, such as constant or hash, when that remaining structure should not be exposed.
  • constant — single fixed string replacement.
  • hash — deterministic replacement for analytics.