Complete the code to list all tables in the current database.
SELECT tablename FROM pg_catalog.pg_tables WHERE schemaname = [1];In PostgreSQL, the default schema where user tables are stored is called public. So, to list all tables, we filter by schemaname = 'public'.
Complete the code to show the first 5 rows of the table named 'employees'.
SELECT * FROM employees [1] 5;
In PostgreSQL, to limit the number of rows returned, we use the LIMIT clause.
Fix the error in the code to rename a table from 'old_name' to 'new_name'.
ALTER TABLE [1] RENAME TO new_name;To rename a table, you specify the current table name after ALTER TABLE. So, use 'old_name' there.
Fill both blanks to create a new database named 'testdb' owned by user 'admin'.
CREATE DATABASE [1] OWNER [2];
The database name goes right after CREATE DATABASE, and the owner username goes after OWNER.
Fill all three blanks to grant SELECT and INSERT privileges on table 'customers' to user 'guest'.
GRANT [1], [2] ON [3] TO guest;
We list the privileges to grant separated by commas, then specify the table name after ON.