Challenge - 5 Problems
psql Command Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2: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
Attempts:
2 left
💡 Hint
The \dt command lists tables in the current database.
✗ Incorrect
The \dt command in psql shows all tables in the current database schema. It does not show databases or table contents.
📝 Syntax
intermediate2: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?
Attempts:
2 left
💡 Hint
psql accepts the database name as the first argument or with -d option.
✗ Incorrect
The simplest ways to connect to a database are 'psql shopdb' or 'psql -d shopdb'. Option C is invalid syntax; option B is invalid.
🔧 Debug
advanced2: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\;
Attempts:
2 left
💡 Hint
Backslash is used for psql commands, not inside SQL statements.
✗ Incorrect
The backslash before the semicolon is not valid SQL syntax. The semicolon alone ends the statement. Backslash commands are separate from SQL.
🧠 Conceptual
advanced2:00remaining
What does the psql command
\x do?You type
\x in the psql prompt. What is the effect?Attempts:
2 left
💡 Hint
Expanded mode changes how query results are displayed.
✗ Incorrect
The \x command toggles expanded output mode, which shows each column on its own line for easier reading of wide tables.
❓ optimization
expert2: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?
Attempts:
2 left
💡 Hint
The \i command runs SQL commands from a file inside psql.
✗ Incorrect
The \i command inside psql reads and executes SQL commands from a file. Option A runs psql from shell, not inside psql. \copy is for data import/export, not SQL scripts. \load is for loading shared libraries.