Wednesday, May 4, 2022

PostgreSQL \d commands versus MySQL's SHOW commands

One type of databases is pretty much the same as any other type of database base, right? 

Well, at one high abstract level that may be true.  But at the level where you have to use the database then things can be radically different.  

For the past several years I have mainly bee focusing on MySQL but my new job is letting me explore PostgreSQL.  I have used PostgreSQL in the past but it has been over a decade since I have done any production work.  And as such I am re-learning some basic commands.

When using the MySQL cli or shell I am used to typing SHOW SCHEMAS; or SHOW DATABASES; when I want to know which schemas/databases are on a given server.  PostgreSQL's psql uses \l.

There are an entire series of \d commands. A \d by itself shows the tables, sequences, and views in a schema.  You use \dt to see the tables, \ds to see the sequences, and \dv to see the views. And \du displays the users.

MySQL uses \g at the end of the command to mark the end of the SQL while in PostgreSQL \g by itself executes the last command. 

And you can have that output in an aligned format or unaligned by toggling the \a command or use \H to see the output in HTML.