Lukas Ĺ alkauskas Lukas Ĺ alkauskas - 1 year ago 177
Python Question

Google BigQuery, create a table from a query result

ok, so we're using Google BigQuery via python API,
my question is how to create a table (new one or overwrite old one) from a query results ? Some docs are here, but I can't find it usefull.

basically, we want to simulate

"SELEC ... INTO ..." from ANSI SQL.

Answer Source

You can do this by specifying a destination table in the query. You would need to use the Jobs.insert API rather than the Jobs.query call, and you should specify writeDisposition=WRITE_APPEND and fill out the destination table.

Here is what the configuration would look like, if you were using the raw API. If you're using Python, the Python client should give accessors to these same fields:

"configuration": {
  "query": {
    "query": "select count(*) from",
    "destinationTable": {
      "projectId": "my_project",
      "datasetId": "my_dataset",
      "tableId": "my_table"
    "createDisposition": "CREATE_IF_NEEDED",
    "writeDisposition": "WRITE_APPEND",
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download