SQL Database Connector for Google Sheets
Introduction
Live records usually sit in a database while the reconciliation happens in a spreadsheet. The SQL connector runs a read-only query through Google Apps Script's JDBC service and writes the result to Flookup Staging, so you can clean, deduplicate or match those rows with the rest of Flookup, then send the changes back through a key column.
Supported databases: PostgreSQL, MySQL, Microsoft SQL Server and Oracle.
It never changes your schema, never deletes rows and does not run on a schedule in this version.
Worked example. One read only query into staging, the reconciliation and the write back are shown in Import SQL Query Results Into Google Sheets Without a CSV.
Before You Start
A SQL pull depends on a network path, a database account and one query. Settle all four before you open the connector card.
- Network. The database firewall must accept Google's JDBC ranges, on a port of 1025 or higher, over TLS 1.2 or later. Google publishes the ranges in its Apps Script JDBC documentation.
- Query. Write a single SELECT or WITH statement that already returns the key column, because write-back cannot use a key the query does not return.
- Account. Use a user that can only read. Add INSERT and UPDATE on the one table you write to if you need write-back and nothing wider.
- Pass. The 14-day trial includes connectors with 50 action credits. A pass is needed after the trial.
If your database sits inside a private network with no public endpoint, the connector cannot reach it. Export the result there and use a CSV join instead.
Network Access
Apps Script connects from Google's servers, so your database firewall must allow Google's published IP ranges for JDBC. The security group also needs a port of 1025 or higher and TLS 1.2 or later.
Use a read-only database user for pulls. If you also want write-back, grant that user INSERT and UPDATE on the target table and nothing wider.
| Database | JDBC URL example |
|---|---|
| PostgreSQL | jdbc:postgresql://db.example.com:5432/analytics |
| MySQL | jdbc:mysql://db.example.com:3306/analytics |
| SQL Server | jdbc:sqlserver://db.example.com:1433;databaseName=analytics |
| Oracle | jdbc:oracle:thin:@//db.example.com:1521/ORCLPDB1 |
Cloud SQL instances work with the standard URL once the instance authorises Google's IP ranges.
Connect the Database
- Enter the JDBC URL, user and password in the SQL database card.
- Enter a single SELECT or WITH query.
- Click Test query to confirm the connection and see the column names.
- Click Save.
Only one statement is allowed. Inserts, updates, deletes and stacked statements are rejected before anything reaches the database. The password is stored with your Google account and is never returned to the sidebar.
Run the Query
Click Pull to staging. The query runs with a cap of 25,000 rows per run on a pass (5,000 on the trial) and the result replaces the staging sheet.
- Values arrive as text, because every column is read as a string. Apply number or date formatting in the sheet after the pull and remember that write-back sends the cell text back to the database.
- The pull reports when the row cap stopped it. Add a filter or a smaller range instead of pulling everything.
- Column headers come from the query, so aliases are fine for a pull.
Query design decides how much cleanup the staging sheet needs. Name the columns you want instead of selecting everything, because a wide table wastes the row budget and hides the fields you actually use.
Filter to the slice you need. A date range, a status or a customer segment keeps the result under the 25,000-row-per-run pass cap (5,000 on the trial) and makes each pull repeatable.
Choose a key that is unique, never reused and not edited by hand. An invoice number works; a customer name does not, because it changes and two customers can share one. Rows with a NULL key cannot be matched, so exclude them in the query.
Write Changes Back
Write-back needs three things: the table name, a key column that the saved query returns and column headers that match real column names.
- Fill in Table for write-back and Key column.
- Edit the staging sheet or clean it with Flookup custom functions.
- Click Preview changes and review the new, changed and unchanged counts.
- Click Apply changes.
Changed rows are updated and new keys are inserted. Rows missing from the staging sheet are never deleted. A run applies at most 500 changes.
If a write fails, changes from that run are not left partly applied. Apply is tied to the preview you just saw: if the staging sheet or the query result changes in between, the write is refused. A preview stays valid for 15 minutes and can be used once.
Each committed change is appended to a Flookup Changes sheet with the timestamp, table, key, field, before value and after value. A rolled-back run writes nothing to the log, because nothing changed.
Aliased columns are read-only for write-back, because the alias is not a real column name. If the saved query hits the 25,000-row-per-run pass cap (5,000 on the trial), update-only runs still work, but new rows are refused, because the connector cannot check whether they already exist. PostgreSQL users may need
?stringtype=unspecified
on the JDBC URL so typed columns accept the values.
Test on a copy first. Point Table for write-back at a scratch table with the same columns, apply one changed row and check the result there. Pointing it at the live table before that test is how a cleanup pass becomes an incident.
When the test passes, change the table name and preview once more. The preview reads the live table, so a column that exists only in the copy will show up as a mismatch before anything is written.
Troubleshooting
| Symptom | Cause and fix |
|---|---|
| Connection refused or timed out | Google's IP ranges are not allowlisted, the port is below 1025 or TLS is older than 1.2. |
| Password authentication failed | Check the user and password. Retry sparingly: Apps Script allows only 100 failed JDBC connections a day for consumer accounts. |
| The query must return the key column | Add the key column to the SELECT list or choose a different key. |
| Column X is not in the saved query | The staging sheet has a column the query does not return. Remove it or add it to the query and pull again. |
| New rows are refused because of the row cap | The saved query returned 25,000 rows on a pass (5,000 on the trial), so it may be hiding existing keys beyond the cap. Narrow the query until it returns every row you stage, then preview again. |
Frequently Asked Questions
Which databases can Flookup connect to?
PostgreSQL, MySQL, Microsoft SQL Server and Oracle, through Google Apps Script's JDBC service. The database must accept connections over TLS 1.2 or later on a port of 1025 or higher.
Why does the connection time out?
Apps Script's servers must be allowed through the database firewall. Authorise Google's published IP ranges and confirm the port is 1025 or higher.
Can Flookup change my database schema?
No. Pulls run a single SELECT. Write-back only inserts new rows and updates changed columns in the table you name and it never deletes records.
Why does PostgreSQL reject a write-back value?
PostgreSQL can refuse text-bound values for typed columns. Add ?stringtype=unspecified to the JDBC URL to let the server infer the type.