PostgreSQL Tutorial: Access PostgreSQL using Excel

October 8, 2023

Summary: You can use Microsoft Excel to access data from a PostgreSQL database using ODBC connector. With ODBC Driver, you can import the data directly into an Excel Spreadsheet and present it as a table. Make sure that you use matching Excel and ODBC Driver, e.g. if you are using the 64-bit version of Excel, you will need to install a 64-bit ODBC Driver.

Install PostgreSQL ODBC Driver

The first step in Excel to PostgreSQL data transfer is to install ODBC Driver. The PostgreSQL ODBC 64-bit driver is available for download. On the machine where the Secure Agent is installed, install the PostgreSQL ODBC driver.

Connect to PostgreSQL from Excel

Click the Data in Excel, then expand the Get Data drop-down list. Click From Other Sources > From ODBC.

Connect Excel to ODBC data source

In the From ODBC dialog, choose your data source name (DSN). If you haven’t configured your ODBC driver yet, you can expand the Advanced Options dialog box and enter the connection string for your data source (without credentials, which are defined in the credentials dialog box in the next step). Additionally, you can enter an SQL statement that will be executed right after establishing a connection to the data source. Click OK.

Choose ODBC data source in Excel

If you’re using a database username or password, select Database and enter your credentials in the dialox bog, then click Connect.

Enter Data Source Credentials

If your database is not password-protected or you’ve already specified your credentials in the ODBC data source settings, select Default or Custom and press Connect.

Excel ODBC custom connection string

Load Data in Microsoft Excel

In the window that appears, select the table you want to retrieve data from, and click Load.

List of tables from ODBC data source

The data from the table will be a displayed in an Excel spreadsheet where you can further work with it.

View the table contents

You have successfully completed to access PostgreSQL data in Excel via ODBC Driver.

comments powered by Disqus