0
0
PostgreSQLquery~20 mins

Foreign data wrappers concept in PostgreSQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Foreign Data Wrapper Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Purpose of Foreign Data Wrappers in PostgreSQL
What is the main purpose of using Foreign Data Wrappers (FDW) in PostgreSQL?
ATo speed up local query execution by caching data internally
BTo create backup copies of local tables automatically
CTo allow PostgreSQL to query and manipulate data stored in external data sources as if they were local tables
DTo encrypt data stored in PostgreSQL tables
Attempts:
2 left
💡 Hint
Think about how PostgreSQL can access data outside its own database.
query_result
intermediate
2:00remaining
Querying Foreign Table Output
Given a foreign table named 'foreign_employees' linked to an external database, what will this query return?
SELECT name, department FROM foreign_employees WHERE department = 'Sales';
AAll employees from the local PostgreSQL database regardless of department
BAll employees from the external source who work in the Sales department
CAn error because foreign tables cannot be filtered
DOnly the names of employees without their departments
Attempts:
2 left
💡 Hint
Foreign tables behave like regular tables in queries.
📝 Syntax
advanced
2:00remaining
Correct Syntax to Create a Foreign Table
Which of the following SQL statements correctly creates a foreign table in PostgreSQL using a foreign data wrapper named 'mysql_fdw'?
ACREATE FOREIGN TABLE employees (id INT, name TEXT) SERVER mysql_server OPTIONS (dbname 'company', table_name 'employees');
BCREATE FOREIGN TABLE employees (id INT, name TEXT) USING mysql_fdw OPTIONS (dbname 'company', table_name 'employees');
CCREATE FOREIGN TABLE employees (id INT, name TEXT) SERVER mysql_fdw OPTIONS (database 'company', table 'employees');
DCREATE FOREIGN TABLE employees (id INT, name TEXT) SERVER mysql_server OPTIONS (database 'company', table_name 'employees');
Attempts:
2 left
💡 Hint
The SERVER clause must reference the foreign server name, and OPTIONS keys are case sensitive.
optimization
advanced
2:00remaining
Improving Performance of Foreign Table Queries
Which approach can improve query performance when accessing large foreign tables in PostgreSQL?
ACreate indexes on the foreign table in the external data source if supported
BUse only SELECT * queries without WHERE clauses
CDisable the foreign data wrapper to speed up queries
DAlways fetch all rows without filtering to reduce overhead
Attempts:
2 left
💡 Hint
Think about how databases speed up queries on large tables.
🔧 Debug
expert
2:00remaining
Diagnosing Foreign Table Query Error
You run this query on a foreign table:
SELECT * FROM foreign_customers WHERE customer_id = 123;

But you get the error:
ERROR:  foreign table "foreign_customers" does not exist

What is the most likely cause?
AThe query syntax is invalid because WHERE clause cannot be used on foreign tables
BThe foreign data wrapper is not installed on the PostgreSQL server
CThe external data source is offline
DThe foreign table 'foreign_customers' was not created or is misspelled in the current schema
Attempts:
2 left
💡 Hint
Check if the table exists in the database schema.