Skip to content

Instantly share code, notes, and snippets.

@afeld
Last active March 19, 2020 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save afeld/0feb015e329c20b2f5682ca028e3374d to your computer and use it in GitHub Desktop.
Save afeld/0feb015e329c20b2f5682ca028e3374d to your computer and use it in GitHub Desktop.
running SQL against Google Sheets

Google Sheets has a QUERY function that can be used for writing SQL queries. It uses the Google Visualization API Query Language, which is unfortunately a pretty limited SQL dialect. A few options for writing more complex SQL queries:

  • Export to CSV and load into a database somewhere
    • Pros: Use whatever database you want
    • Cons: Have to re-export every time the data is updated
  • Load into BigTable
    • Pros: Automatically updates
    • Cons: Requires some Google Cloud setup
  • Load into Google Colaboratory ("Colab")
    • Pros: Very flexible, as you can use SQL, Pandas, or any other Python code/packages
    • Cons: Jupyter Notebooks (which Colab is built on) can take a little getting used to

The Notebook above shows the quickest path to getting that data into SQLite on Google Colab, which can be done in a matter of minutes. To get started, open the Notebook below in Google Colab.

Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment