gsheets
gsheets · Read and write Google Sheets from PostgreSQL.
Overview
Usage
Sources:
gsheets lets SQL sessions read from and write to Google Sheets. It is useful for small integration, import, and export workflows where the database server can reach Google APIs and the session can supply an OAuth access token.
Core Workflow
Create the extension, complete the upstream authentication flow, and set the resulting token for the current session:
read_sheet is polymorphic: the caller supplies the returned column definition. The first argument accepts a spreadsheet ID or URL.
Write rows with write_sheet. Supplying no spreadsheet_id asks the extension to create a spreadsheet; otherwise the JSON options select an existing spreadsheet and sheet.
User-Facing Objects
gsheets_auth(): starts the OAuth authentication flow described by upstream.gsheets.access_token: session setting containing the Google access token.read_sheet(spreadsheet_id/url text, sheet_name text DEFAULT 'Sheet1', header boolean DEFAULT true): reads rows; declare the expected record columns in the query.write_sheet(data anyelement, options jsonb DEFAULT '{}'): writes values or composite rows. Options includespreadsheet_id,sheet_name, andheader.
Operational Notes
The extension links to libcurl and performs external network requests from the PostgreSQL server process. Authentication requires an interactive URL/token flow, so plan explicitly for headless servers and token renewal. Keep gsheets.access_token out of logs and persistent role/database settings, and grant use of the extension only to roles allowed to access the target sheets. No preload setting is documented. Test API errors, rate limits, partial writes, and retry behavior before using write_sheet in automated jobs.