Database Reference
In-Depth Information
"SELECT \"${kind}\" kind, \"${day}\" day"
done
done
Now take a quick look at what you created:
$ bq query "SELECT table_id FROM ch11.__TABLES __
WHERE REGEXP_MATCH(table_id, r'^(a|b)_')"
+------------+
| table_id |
+------------+
| a_20131108 |
| . . . |
| a_20131114 |
| b_20131108 |
| . . . |
| b_20131114 |
+------------+
You can see how to use the metatable to locate the tables rather than just
simply listing the dataset.
If the list of tables in a query depends on the input or needs to be resolved
just before running the query, you could now achieve that by issuing two
queries. First, query the dataset metatable, and then use the results of
that query to construct the actual query over your tables. The script
two_phase.py in the examples for this chapter performs this two-step
query. Here is the relevant bit:
# Query the metatable for a list of matching tables.
resp = bq.jobs().query(
projectId=PROJECT_ID,
body={'query':('SELECT table_id FROM
ch11.__TABLES__ '
'WHERE LEFT(table_id, 2) = "%s_"'
% (sys.argv[1]))}
).execute()
# Build the list of tables.
tables = ', '.join(['ch11.' + cell(r, 0) for r in
resp['rows']])
Search WWH ::




Custom Search