Introduction
This is an article where the main focus is showing about how to describe a certain table in PostgreSQL database server. There is a certain command for getting the table description. The execution of the command is in the PostgreSQL command console. In this article, the demonstration for describing a table exist in PostgreSQL Database Server is using a machine running with Microsoft Windows 10 as the operating system.
How to Describe Table in PostgreSQL Database
In this context, the table description will be for a table with the name of ‘users’. The following are the sequences for achieving the purpose of describing a certain table in PostgreSQL database server :
-
At first, just make sure that the PostgreSQL database server is running.
-
Continue on the previous step, the most important thing is to be able to connect to PostgreSQL command console. In this case, the example is using PostgreSQL database server available in Microsoft Windows 10. The execution for logging in and connect to the PostgreSQL database server is possible using the Command Prompt tool. It is a tool available in Microsoft Windows-based operating system for executing a command in a text-based line. The following is the execution of the Command Prompt :
Microsoft Windows [Version 10.0.18363.628] (c) 2019 Microsoft Corporation. All rights reserved. C:\Users\Personal>
-
Next, just login to the PostgreSQL database server as follows :
C:\Users\Personal>psql -Upostgres Password for user postgres: psql (14.2) WARNING: Console code page (437) differs from Windows code page (1252) 8-bit characters might not work correctly. See psql reference page "Notes for Windows users" for details. Type "help" for help. postgres=#
-
After successfully logging in to the PostgreSQL database server, a PostgreSQL command console will appear. Soon after that, type the following command to connect to the database :
postgres=# \c db_apps You are now connected to database "db_apps" as user "postgres". db_apps=#
- Before describing the table, just list all the available tables in the database by typing the following query or command :
db_apps=# \dt List of relations Schema | Name | Type | Owner --------+----------+-------+---------- public | users | table | postgres public | products | table | postgres (2 rows) db_apps=#
-
Finally, the final steps, following the command execution above, just type the following query or command to describe a certain table. In this case, the chosen table is the table with the name of ‘users’ :
db_apps=# \d users; user_id | integer | | not null | nextval('users_sequence'::regclass) email_id | character varying(55) | | | password | character varying(55) | | | first_name | character varying(55) | | | last_name | character varying(55) | | | db_apps=#