Extensions add extra features to your database that are not included by default. They help you do special tasks easily.
Extensions (pg_trgm, uuid-ossp, hstore) in PostgreSQL
CREATE EXTENSION extension_name;Replace extension_name with the name of the extension you want.
You need proper permissions to add extensions.
CREATE EXTENSION pg_trgm;CREATE EXTENSION "uuid-ossp";
CREATE EXTENSION hstore;This script adds the three extensions if they are not already installed. Then it creates a table using UUIDs for IDs, hstore for flexible data, and uses pg_trgm to find similar text.
CREATE EXTENSION IF NOT EXISTS pg_trgm; CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; CREATE EXTENSION IF NOT EXISTS hstore; -- Create a table using these extensions CREATE TABLE example ( id UUID DEFAULT uuid_generate_v4() PRIMARY KEY, data hstore, description TEXT ); -- Insert sample data INSERT INTO example (data, description) VALUES ('"color"=>"blue", "size"=>"medium"', 'A blue medium item'); -- Search using pg_trgm similarity SELECT id, description FROM example WHERE description % 'blue';
Use IF NOT EXISTS to avoid errors if the extension is already installed.
Extensions like uuid-ossp provide useful functions such as uuid_generate_v4() to create unique IDs.
The pg_trgm extension helps with fast and fuzzy text searches using the % operator.
Extensions add extra tools to your PostgreSQL database.
pg_trgm helps with fast text similarity searches.
uuid-ossp helps generate unique IDs automatically.
hstore lets you store flexible key-value data in one column.