In this article:

How to Import PostgreSQL Data to Google Sheets [Step by Step Tutorial]

>Click here to import PostgreSQL Data to a Lido Spreadsheet

PostgreSQL is one of the popular open source SQL relational databases. According to its website, it has over 30 years of active development that has earned it a strong reputation for reliability, feature robustness, and performance. In this tutorial, we will learn two methods for importing PostgreSQL data to Google Sheets, and then we also learn how to import PostgreSQL data using the Lido app. Are you ready?

How to connect to PostgreSQL databases

To connect to a PostgreSQL database, you need the following information: 

  • server_url is for the url of the PostgreSQL server
  • port_number is the port number for the PostgreSQL server, usually set at 5432
  • database_name is the name of the PostgreSQL database
  • username is the username for access
  • password is the corresponding password for the given username
  • table_title is the name of the table you want to load into a spreadsheet

Alternatively, you can create a connection string with the following format:

postgres://username:password@server_url:port_number/database_name

The better syntax will depend on the importation method that you choose.

How to import PostgreSQL data using an add-on

As we have emphasized in our blog post about Google Sheets add-ons, you have a wide variety of choices in selecting an add-on that will boost the capabilities of your spreadsheet. For this tutorial, we will use the SyncWith | Any API add-on.

SyncWith app
SyncWith app

After installing the add-on, the sidebar appears as below. It shows a list of platforms that it can import to Google Sheets, and has a search bar to quickly find the platform you want to access. 

SyncWith add-on sidebar
SyncWith add-on sidebar

Once you select PostgreSQL, the list of access details will show up. You can either add the connection parameters or the connection string.

Connection Parameters
SyncWith add-on, listing the connection parameters needed. You can opt to include the connection string instead.

Besides the connection parameters, you will also need to provide an SQL query. One example query you can use is the following:

SELECT * FROM table_name

We have also written two articles detailing the possible SQL Queries that you can use. Check them out below:

SQL Basics: Introduction to Queries - Lido.app

Advanced SQL Queries & Tutorial - Lido.app 

This specific query will import all the columns and rows from the table_name

SyncWith add-on. SQL query is needed to run the sidebar.
SyncWith add-on. SQL query is needed to run the sidebar.

Once you have set the sidebar, click Insert at the bottom of the sidebar. When you click the arrow beside the Insert button, it will also give you an option to insert the data at a certain selected cell of your active sheet. You can get the following result:

SyncWith output showing data from PostgreSQL database
SyncWith output showing data from PostgreSQL database

SyncWith inserts a checkbox at the first cell that you can check if you want to manually refresh the spreadsheet. 

How to import PostgreSQL data using Google Apps Script

Being a popular implementation of SQL, PostgreSQL data can also be imported using other methods that work for SQL-based databases such as MySQL. One way to do so is to create a custom Google Apps Script. If you are tech-savvy, you may prefer this option because it removes a middleman that will process the data before it reaches your spreadsheet. 

Check the following tutorial to access the code and tweak it as needed:

How to Import Data from a MySQL Database to Google Sheets

How to import PostgreSQL data using Lido

Unlike Google Sheets, Lido has a built-in feature that allows you to directly import data from popular eCommerce and marketing platforms, which includes PostgreSQL databases. To do so, click the Data icon on the upper-left side of Lido, and then select PostgreSQL

Lido interface
Lido interface, showing the Data sidebar and the list of sources it can import, including PostgreSQL

The left sidebar changes to a list of textboxes where you must input the connection parameters. You have to whitelist the IP addresses shown in the sidebar in your PostgreSQL database. 

Lido data sidebar, PostgreSQL option.
Data sidebar, PostgreSQL option. A set of checkboxes appear where you input the connection parameters.

When you are done, click Connect

Connecting Screen
Screen that appears while Lido tries to connect to your PostgreSQL database.

When Lido successfully connects to your PostgreSQL database, it will load the Dataset Editor. This is where you can select the data to be imported. Select the database on the drop-down box on the left side, then click Open Data Explorer.

Lido Dataset Editor
Dataset Editor, the database is yet to be selected on the left side of the editor

A large window labeled Select data will appear, where you can select the table to load on the left side and then select the columns listed under that table. For our example, we want to load all of the columns. You can also opt not to load all the rows by specifying the range of rows on the lower-left side of the box. You can use that feature to also check how many rows are stored in the selected table. Once you are done, click Save.

Lido select data window.
Select data window, where you can select the specific table and columns to load

The Select data window will close, and you will go back to Database Editor, but with a preview of the PostgreSQL data you will load. If you are satisfied, click Save dataset & add view. 

Dataset Editor, with a preview
Dataset Editor, with a preview of the data to be loaded

The PostgreSQL data will then be loaded into your Lido spreadsheet: 

Lido spreadsheet with PostgreSQL data loaded
Lido spreadsheet with PostgreSQL data loaded

Have you noticed something? Unlike in the Google Sheets add-on we use, we do not need prior knowledge of the tables stored in the database nor even the basics of SQL. This makes using Lado a breeze for non-technical teams who need to access otherwise complicated PostgreSQL data! 

Interested? Click here to get started today!

Related Articles

-Filter SQL Data Before Importing to Google Sheets

-Import MySQL Database to Google Sheets

-Export SQL Data to Google Sheets

-SQL Basics

-Most Useful SQL Functions

Automate repetitive tasks with Lido

Save hours on repetitive and tedious work. Lido is a new spreadsheet that connects your spreadsheets, forms, PDFs, and email inbox.

Trigger
Action
Select trigger
When a cell value in Google Sheets changes
Check Google Sheets for today's date
When a new row is added to Google Sheets
On new Google Form submission
Send me a daily reminder
On new Typeform submission
When a cell value in database changes
Check database for today's date
When a new row is added in database
When a new HubSpot customer is created
Select action
ADDCALENDAREVENT
Creates a one- or multiple-day calendar event with optional attendees
ADDHUBSPOT
Adds an object to Hubspot
ADDSLACKCHANNEL
Create a Slack channel, and optionally add a topic or members
CALLURL
Makes any HTTP request
CREATEGOOGLEDOC
Replaces [@column_name] values in a Google Doc with the corresponding table row's values
CREATEPDF
Replaces [@column_name] values in a Google Doc with the corresponding table row's values, then export it as a PDF
FETCH
Makes any HTTP request and returns the response
INSERTROWS
Inserts given array below defined values in given worksheet
SENDGMAIL
Sends an email using your Google account
SENDOUTLOOK
Sends an email using your Microsoft Outlook account
SENDSLACK
Sends a Slack message
SENDSMS
Sends an SMS message using your Twilio account
UPDATECELL
Updates cells with given values
UPDATEHUBSPOT
Updates a property of a Hubspot object
Trigger is required
Action is required
Get started