Using Postgres if you already know MySQL

Ben Garvey
2 min readAug 8, 2018

--

Does your search history look like this?

show tables in postgresuse database in postgresdescribe in postgresmom's friend actress from Sharp Objects

I am a long time MySQL user. All of its admin commands are simple and make sense. PostgreSQL’s are complex, powerful, and impossible to remember.

I’m writing this for you and for myself.

There are a lot of things I don’t get about Postgres, but I am converted. Performance beats MySQL for almost any use case and there are a ton of great things you can do.

But that’s not what this is about. This post is meant to erase the friction of getting started because you’re querying the wrong schema and if you could just type use prod; use users; you’d be in business.

Let’s get through this together.

When you want to type show databases, type \l instead

I don’t even know what \l stands for. I assume it’s “list,” but I’m not even going to look it up.

One important thing you should understand about Postgres is that you’re always connected to a specific database. Databases are one level higher than they are in MySQL and you can’t query across them. In its place are schemas, and your queries can span across multiple schemas if you have sufficient privileges. Postgres schema = MySQL database.

When you want to type use databasename, type set search_path to schemaname or \c databasename

If you don’t know the schema name, type select schema_name
from information_schema.schemata
or type \dn.

When you want to type show tables, type \dt instead

Does \dt stand for “Da Tables?” Probably. If \dt still doesn’t work, make sure your search path is set to a specific schema name (see above).

When you want to type describe tablename , type \d+ tablename instead

That’s pretty straightforward.

When you want to know who the mom’s friend is from Sharp Objects (enemy, really), she’s played by Elizabeth Perkins, who was also in Big with Tom Hanks

--

--