0
0
PostgreSQLquery~20 mins

Extensions (pg_trgm, uuid-ossp, hstore) in PostgreSQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Extension Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Using pg_trgm to find similar words
Given a table products with a column name, which query will return product names similar to 'apple' using the pg_trgm extension?
PostgreSQL
SELECT name FROM products WHERE name % 'apple';
ASELECT name FROM products WHERE name % 'apple';
BSELECT name FROM products WHERE similarity(name, 'apple') > 0.3;
CSELECT name FROM products WHERE name LIKE '%apple%';
DSELECT name FROM products WHERE name = 'apple';
Attempts:
2 left
💡 Hint
The pg_trgm extension provides the % operator for similarity search.
📝 Syntax
intermediate
1:30remaining
Correct syntax to generate a UUID using uuid-ossp
Which of the following SQL statements correctly generates a version 4 UUID using the uuid-ossp extension?
ASELECT generate_uuid_v4();
BSELECT uuid_generate_v4();
CSELECT uuid_v4_generate();
DSELECT generate_v4_uuid();
Attempts:
2 left
💡 Hint
The uuid-ossp extension provides functions starting with 'uuid_generate_'.
query_result
advanced
2:30remaining
Querying hstore data for a specific key
Given a table settings with a column config of type hstore, which query returns all rows where the key 'theme' has the value 'dark'?
ASELECT * FROM settings WHERE config ->> 'theme' = 'dark';
BSELECT * FROM settings WHERE config -> 'theme' = 'dark';
CSELECT * FROM settings WHERE config['theme'] = 'dark';
DSELECT * FROM settings WHERE config @> 'theme=>dark';
Attempts:
2 left
💡 Hint
The @> operator checks if the hstore contains a key-value pair.
optimization
advanced
2:30remaining
Improving search performance with pg_trgm
You want to speed up similarity searches on the description column of a documents table using pg_trgm. Which index type is best to create?
ACREATE INDEX trgm_idx ON documents USING gist (description gist_trgm_ops);
BCREATE INDEX trgm_idx ON documents USING btree (description);
CCREATE INDEX trgm_idx ON documents USING gin (description gin_trgm_ops);
DCREATE INDEX trgm_idx ON documents USING hash (description);
Attempts:
2 left
💡 Hint
pg_trgm works best with GIN or GiST indexes using gin_trgm_ops or gist_trgm_ops.
🔧 Debug
expert
3:00remaining
Debugging hstore key retrieval error
You run this query: SELECT config ->> 'language' FROM settings; but get an error: operator does not exist: hstore ->> unknown. What is the cause?
PostgreSQL
SELECT config ->> 'language' FROM settings;
AThe hstore extension is not enabled in the database.
BThe ->> operator is not defined for hstore; use -> instead.
CThe config column is not of type hstore but json or jsonb.
DThe ->> operator requires the key to be cast to text explicitly.
Attempts:
2 left
💡 Hint
Check if the hstore extension is installed and enabled.