PostgreSQL Meta-Command using psql: Command Information -IV

This is in continuation of My last blog about Meta Commands in PostgreSQL. In last blog I have explained what a Meta command and how to list databases. In next few blogs we will explore few of Meta commands. Lets start exploring schemas.

Visit this series of last blog for other command.

The command we will explore here is:
1. \dt
2. CREATE TABLE
3. \d

Once we are able to connect to our database using \c and connect to our schema using set search_path, we can list all tables of that particular schema using \dt

Output lists all relations of schema

We can also use CREATE TABLE statement to create a table. We will create a table writer which will hold few attributes of blog writer.

Create statement of table writer

We will try \dt again to see the updated list. We can see both the table name posts & writer. postgresblogs are the schema for both the table and postgres user is owner of them.

Updated output of \dt

Since, we have created a table, we would like to see the structure of this table at any point of time. We can easily do that using help of \d

Description of both posts & writer table

If we analyze the output, we can easily see that the output is informative. It is listing column name with it’s datatype and lengths (precision), character set information using collation and other info in default column of the output.

In next blog we will explore further commands which we can run in psql

Leave a Reply

Your email address will not be published.