The answer to this question depends heavily on what you’re trying to connect to Google Sheets and may require some additional setup if you’re trying to connect Sheets to an internal database instance, which isn’t exposed to the internet.
For services which are exposed to the internet, there’s a handful of extensions which can handle pushing and pulling data from different database services and SAAS applications. Coefficient works well (disclaimer: I'm a software engineer there). It has connectors for a large array of different services and databases, with the relevant ones to your question currently being:
- MySQL
- Redshift
- PostgreSQL
- CSV (In the worst-case scenario, if your
platform isn’t supported yet, you could export to CSV and then import
the CSV automatically)
We’re constantly adding more connectors as well, and you can mix, match, and manage them all within the same sheet. We also provide a lot of documentation for their product and ideas on how to leverage Sheets reporting for the different platforms they support in their blog.
If you’d like to avoid using 3rd party tools, you can utilize App Scripts to craft a custom function to pull down data for you from an external SQL instance. Just a note: the scripts they provide as examples are for connecting to a google cloud instance. You’ll want to use Jdbc.getConnection(url)
instead of Jdbc.getCloudSqlConnection(url)
if you’re connecting to a non-Google Cloud database. Just like with the Add-on solution, you’ll need to make sure that any databases you’re hosting and wish to access, that they are accessible from the internet (the linked google documentation has more info on that).
An advantage to this solution is that it’s VERY customizable and can be re-used. It’s also very intuitive for Sheets veterans, as the call can be made just like a regular sheets function.
The caveat is that it’s a solution that requires some development understanding to implement in a way that is reusable and is intuitive for all users. The “Read from the Database” example that Google provides in their documentation takes no parameters, and just dumps out all the data for one table. Creating a new function for each table you want to pull from, each time you want to load a new table probably isn’t on your to-do list, so you’ll likely want to add in parameters for which server to connect to, which port, which database, which columns to return, and any filters to be applied (or maybe what SQL command to run?).
But at that point it’s become much less accessible for non-technical users, and you’re recreating a package that others like Coefficient have already put the time, resources, and understanding to develop.