Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
December 12, 2022 07:55 am GMT

In Postgres, perform a partial match on an encrypted column value

In Postgres, you can execute a partial match on an encrypted column value. This will, however, necessitate the usage of a trigram index and the pg_trgm extension. Here's an illustration:

-- Enable the pg_trgm extensionCREATE EXTENSION pg_trgm;-- Create a table with an encrypted columnCREATE TABLE encrypted_data (  id SERIAL PRIMARY KEY,  encrypted_column TEXT ENCRYPTED USING 'aes');-- Insert some encrypted dataINSERT INTO encrypted_data (encrypted_column)VALUES ('encrypted value 1'), ('encrypted value 2');-- Create a trigram index on the encrypted columnCREATE INDEX encrypted_data_encrypted_column_trigram_idxON encrypted_data USING gin (encrypted_column gin_trgm_ops);-- Perform a partial match on the encrypted columnSELECT *FROM encrypted_dataWHERE encrypted_column % 'encrypt';

This will return all rows that have the substring 'encrypt' in the encrypted encrypted_column value.


Original Link: https://dev.to/asifroyal/in-postgres-perform-a-partial-match-on-an-encrypted-column-value-5bal

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To