Updated on 2024-12-13 GMT+08:00

Data Masking Functions

Data masking refers to the process of distorting sensitive information based on masking rules to protect sensitive privacy data.

  • mask_first_n(string str[, int n]) →varchar

    Description: Returns the masked version of a string. The first n values are masked. Uppercase letters are converted to X, lowercase letters to x, and digits to n.

    select mask_first_n('Aa12-5678-8765-4321', 4);
            _col0        
    ---------------------
     Xxnn-5678-8765-4321 
    (1 row)
  • mask_last_n(string str[, int n]) →varchar

    Description: Returns the masked version of a string. The last n values are masked. Uppercase letters are converted to X, lowercase letters to x, and digits to n.

    select mask_last_n('1234-5678-8765-Hh21', 4);
            _col0        
    ---------------------
     1234-5678-8765-Xxnn 
    (1 row)     
  • mask_show_first_n(string str[, int n]) →varchar

    Description: Returns the masked version of a string. Only the first n characters are displayed. Uppercase letters are converted to X, lowercase letters to x, and digits to n.

    select mask_show_first_n('1234-5678-8765-4321',4);
            _col0        
    ---------------------
     1234-nnnn-nnnn-nnnn 
    (1 row)
  • mask_show_flairst_n(string str[, int n]) →varchar

    Description: Returns the masked version of a string. Only the last n characters are displayed. Uppercase letters are converted to X, lowercase letters to x, and digits to n.

    select mask_show_last_n('1234-5678-8765-4321',4);
            _col0        
    ---------------------
     nnnn-nnnn-nnnn-4321 
    (1 row))
  • mask_hash(string|char|varchar str) →varchar

    Description: Returns a hash value of a string. Hash values are consistent and can be used to join masked values across tables. For a non-string, NULL is returned.

    select mask_hash('panda');
                                  _col0                               
    ------------------------------------------------------------------
     a7cdf5d0586b392473dd0cd08c9ba833240006a8a7310bf9bc8bf1aefdfaeadb 
    (1 row)