What are common psql commands?

Here are some common psql commands that you can use in the PostgreSQL interactive terminal:

  1. Connect to a Database:

    \c database_name
  2. List Databases:

    \l
  3. List Tables:

    \dt
  4. Describe a Table:

    \d table_name
  5. Execute SQL Queries:

    SELECT * FROM table_name;
  6. Insert Data:

    INSERT INTO table_name (column1, column2) VALUES (value1, value2);
  7. Update Data:

    UPDATE table_name SET column1 = value1 WHERE condition;
  8. Delete Data:

    DELETE FROM table_name WHERE condition;
  9. Quit psql:

    \q
  10. Show Current User:

    SELECT current_user;
  11. Show Current Database:

    SELECT current_database();
  12. List All Users:

    \du

These commands provide a foundation for interacting with PostgreSQL databases using the psql command-line interface.

0 Comments

no data
Be the first to share your comment!