Get table id from lookup query

I would like to check if the table range only covers one day (i.e. we don't accidentally put records in the wrong table).

We now have tables that look like this:

Table: sometable_20140506

pst_date   | pst_hour | ...
2014-05-06 | 10       | ...
2014-05-06 | 10       | ...
2014-05-06 | 11       | ...
2014-05-06 | 11       | ...
2014-05-06 | 12       | ...

      

And I would like to find any tables where there is more than one unique value for pst_date, eg. something like:

SELECT table_id, COUNT(*) AS num_dates

FROM
    (SELECT
    table_id,
    pst_date
    FROM
    (TABLE_DATE_RANGE(somedataset.sometable_, 
                      TIMESTAMP('2014-05-06'),
                      TIMESTAMP('2014-06-06')))
    GROUP BY table_id, pst_date)
HAVING COUNT(*) > 1
GROUP BY table_id

      

You can get table_id

in TABLE_QUERY

by simply wondering if you can get it when choosing out TABLE_QUERY

.

+3


source to share





All Articles