Javatpoint Logo
Javatpoint Logo

PostgreSQL Describe Table

In this section, we are going to discuss how to describe a table in PostgreSQL.

In PostgreSQL, to find the information on columns of a table, we can use the describe command query in two different ways, which are as follows:

  • PostgreSQL describe table using pgAdmin 4
  • PostgreSQL Describe table using psql

Note: In PostgreSQL, we cannot have the direct command to Describe the table, but using MySQL, we use the DESCRIBE command directly to identify the information on the columns of a specific table.

PostgreSQL DESCRIBE TABLE using pgAdmin 4

In pgAdmin 4, we are going to use the information_schema for describing the tables.

Here, the information schema itself is a schema that is automatically present in all databases and called information_schema. And by default, it is not available in the schema search path. Thus, if we want to access all objects, we will use it through its qualified names.

The user gets all the advantages of the particular schema if the owner of the information schema is the original database user.

Meanwhile, in the information schema, the names of some of the objects are generic names, which might be happened in user applications or the software. Therefore, we should be alert if we need to place the information schema on the path.

For this, we will use the SELECT command in the information_schema database for quering the column_names of the columns table.

For example, the below query will return all column names of the customer table:

SQL Query in PgAdmin4

PostgreSQL Describe Table

The table Structure

After executing the Select command, we can see the columns_name present in the Customer table.

PostgreSQL Describe Table

PostgreSQL describe table using psql

In psql, we can get the information of a table with the help of the below command and to describe the particular tables in the current database:

To get the list of tables, we will follow the below steps:

Step1

  • Open the SQL shell (psql), which appeared with the necessary details. After that, we will log into the Postgres database server using the password which we created during the installation process of PostgreSQL.
  • And we are connected to the Postgres server as we can see in the below screenshot:
PostgreSQL Describe Table

Step2

  • Now, we will connect to the specific database server which we created earlier that is javatpoint and with the help of below command:

PostgreSQL Describe Table

Step3

  • Finally, we will execute the Describe table command to see that the particular table information.

Note: The \d command is used to describe a table such as a type, column, modifiers of columns, and so on.

Output

The following screenshot explains it more clearly:

PostgreSQL Describe Table
Next TopicPostgreSQL Schema




Youtube For Videos Join Our Youtube Channel: Join Now

Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA