0
0
PostgreSQLquery~20 mins

psql command-line tool basics in PostgreSQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
psql Command Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What is the output of this psql command?
You run the command \dt inside the psql tool connected to a database with three tables: users, orders, and products. What will be displayed?
PostgreSQL
\dt
AA list of all databases available on the server
BAn error saying '\dt' is not recognized
CA list showing the three tables: users, orders, products with their schema and type
DThe content of the users table
Attempts:
2 left
💡 Hint
The \dt command lists tables in the current database.
📝 Syntax
intermediate
2:00remaining
Which psql command correctly connects to a database named 'shopdb'?
You want to connect to the database named 'shopdb' using psql. Which command will do this?
Apsql -d shopdb
Bpsql connect shopdb
Cpsql --database=shopdb
Dpsql shopdb
Attempts:
2 left
💡 Hint
psql accepts the database name as the first argument or with -d option.
🔧 Debug
advanced
2:00remaining
Why does this psql command fail?
You run the command SELECT * FROM users\; inside psql and get a syntax error. Why?
PostgreSQL
SELECT * FROM users\;
AThe semicolon is missing at the end of the statement
Bpsql commands cannot be run inside SQL statements
CThe table 'users' does not exist
DThe backslash before the semicolon is invalid syntax in SQL
Attempts:
2 left
💡 Hint
Backslash is used for psql commands, not inside SQL statements.
🧠 Conceptual
advanced
2:00remaining
What does the psql command \x do?
You type \x in the psql prompt. What is the effect?
AIt toggles expanded output mode, showing query results vertically
BIt exits the psql tool
CIt shows the current database connection info
DIt lists all indexes in the current database
Attempts:
2 left
💡 Hint
Expanded mode changes how query results are displayed.
optimization
expert
2:00remaining
Which psql command efficiently imports a large SQL file named 'backup.sql' into the current database?
You want to load a large SQL dump file 'backup.sql' into your current database using psql. Which command is best?
A\i backup.sql
B\load backup.sql
Cpsql -f backup.sql
D\copy backup.sql
Attempts:
2 left
💡 Hint
The \i command runs SQL commands from a file inside psql.