How to open a PostgreSQL database in Jupyter notebook?

To load an SQLite database we use the following code.

%load_ext sql
%sql sqlite:///factbook.db

To see the available tables we use this

SELECT * FROM sqlite_master;

My question is how can I open a PostgreSQL database file in the Jupyter notebook?

I think you can find your answer here.

Thanks for the reply!

I have read this article before. It says the way to connect the PostgreSQL database in a local computer using a PGadmin user id and password. But I wanted to know how can I connect to a PostgreSQL database file (file type = .db) in a jupyter notebook just like we did for sqlite in the below code?

%load_ext sql
%sql sqlite:///factbook.db

Hi @rakibulislammm

The instructions should be there in the content/ mission that explains installation or working with PostgreSQL

Syntax for connection is - postgresql://username:[email protected]/dbname

let’s say the username, password, and database name, all are "postgres". The connection string would look as below.

%load_ext sql

%sql postgresql://postgres:[email protected]/postgres