In PostgreSQL, you can use the \d command within the psql command-line tool to get information about a table, similar to Oracle's DESCRIBE TABLE command. Here's how you can use it with an example:
Connect to PostgreSQL:
Open a terminal window and use the
psqlcommand to connect to your PostgreSQL database. Replaceyour_databasewith the actual name of your database, and provide the appropriate credentials.sh
psql -h localhost -U your_username -d your_database
Use the \d Command:
Once connected to the database, you can use the \d command followed by the table name to get information about that table. For example, to get information about a table named employees, you can run:
sql
\d employeesThis will display information about the
employeestable, including its columns, data types, constraints, and indexes.
Here's an example output of using the \d command:
sql
Table "public.employees"
Column | Type | Collation | Nullable | Default
---------+-----------------------+-----------+----------+---------
emp_id | integer | | not null |
emp_name| character varying(50) | | |
emp_age | integer | | |
Indexes:
"employees_pkey" PRIMARY KEY, btree (emp_id)
The output includes information about the columns, data types, constraints, and indexes associated with the table.
Remember to replace your_username, your_database, and employees with your actual values. The \d command is a useful tool for quickly inspecting the structure of tables in PostgreSQL from the command line.
Comments
Post a Comment