google-bigquery

BigQuery check if table exists or not

ぃ、小莉子 提交于 2020-05-14 18:23:06
问题 I'm using C# to dynamically construct a query based on a response from the bigquery api tables endpoint. I'm trying to calculate active users which works, but only if I select every table with .* . My question is quite simple really, is there a way to check if a table exists within BigQuery SQL? 回答1: There are metatables called __TABLES__ and __TABLES_SUMMARY__ You can run a query like: SELECT size_bytes FROM <dataset>.__TABLES__ WHERE table_id='mytablename' The __TABLES__ portion of that

BigQuery Standard SQL: Delete Duplicates from Table

佐手、 提交于 2020-05-11 07:48:11
问题 I am using below query to delete duplicates records from bigquery using standard sql. but it is throwing error with cte as ( select * ,row_number()over (partition by CallRailCallId order by CallRailCallId) as rn from `encoremarketingtest.EncoreMarketingTest.CallRailCall2` ) delete from cte where rn>1 Query Failed Error: Syntax error: Expected "(" or keyword SELECT but got keyword DELETE at [5:5] Could anyone help me on the correct approach in BigQuery? 回答1: Option #1 CREATE OR REPLACE TABLE

BigQuery Standard SQL: Delete Duplicates from Table

帅比萌擦擦* 提交于 2020-05-11 07:48:05
问题 I am using below query to delete duplicates records from bigquery using standard sql. but it is throwing error with cte as ( select * ,row_number()over (partition by CallRailCallId order by CallRailCallId) as rn from `encoremarketingtest.EncoreMarketingTest.CallRailCall2` ) delete from cte where rn>1 Query Failed Error: Syntax error: Expected "(" or keyword SELECT but got keyword DELETE at [5:5] Could anyone help me on the correct approach in BigQuery? 回答1: Option #1 CREATE OR REPLACE TABLE

milliseconds format to parse a datetime?

蓝咒 提交于 2020-05-09 17:14:51
问题 I need to parse a datetime contains milliseconds for matching the max value in a field containing this datetimes. For example: #standardSQL SELECT PARSE_DATETIME('%Y-%m-%d %H:%M:%S.%u','2017-08-18 16:04:40.890') Any suggestions? Thanks in advance. UPDATE : Convert to milliseconds, suddendly MAX() . #standardSQL WITH Input AS ( SELECT date FROM UNNEST([ DATETIME '2017-08-18 16:04:40.890', DATETIME '2017-07-27 11:09:10.347', DATETIME '2017-08-22 13:17:34.727', DATETIME '2017-08-22 13:17:34.737'

Continue existing table until end of month with forecasted data and update daily

风流意气都作罢 提交于 2020-05-08 19:55:05
问题 I'd like to create a new table in Google Big Query with existing daily revenue data and extend this new table with forecast data which is based on the existing data and needs to be created. Once new actual data exists for a certain day it overrides the forecast data for that day. Also, the forecast data until the end of the month is then updated again. So far, I came up with the following, which generates an error message : Scalar subquery produced more than one element SELECT date, sum(yl

How to find, list, or search resources across services (APIs) and projects in Google Cloud Platform?

不羁的心 提交于 2020-05-08 05:55:08
问题 In Google Cloud Platform (GCP), you can use list APIs or commands to list resources in a given project for a given type in a given service, like BigQuery datasets or compute instances. But how to find or search resources across types, services, or even projects? 回答1: You can use search-all-resources to search all the resources across services (or APIs) and projects for a given organization, folder, or project. To search all the resources in a project with number 123: $ gcloud beta asset

BigQuery autodetect doesn't work with inconsistent json?

浪尽此生 提交于 2020-04-30 10:16:25
问题 I'm trying to upload JSON to BigQuery, with --autodetect so I don't have to manually discover and write out the whole schema. The rows of JSON don't all have the same form, and so fields are introduced in later rows that aren't in earlier rows. Unfortunately I get the following failure: Upload complete. Waiting on bqjob_r1aa6e3302cfc399a_000001712c8ea62b_1 ... (1s) Current status: DONE BigQuery error in load operation: Error processing job '[...]:bqjob_r1aa6e3302cfc399a_000001712c8ea62b_1':

BigQuery autodetect doesn't work with inconsistent json?

大兔子大兔子 提交于 2020-04-30 10:16:07
问题 I'm trying to upload JSON to BigQuery, with --autodetect so I don't have to manually discover and write out the whole schema. The rows of JSON don't all have the same form, and so fields are introduced in later rows that aren't in earlier rows. Unfortunately I get the following failure: Upload complete. Waiting on bqjob_r1aa6e3302cfc399a_000001712c8ea62b_1 ... (1s) Current status: DONE BigQuery error in load operation: Error processing job '[...]:bqjob_r1aa6e3302cfc399a_000001712c8ea62b_1':

External_query with dynamic query - Error: Connection argument in EXTERNAL_QUERY must be a literal string or query parameter

心不动则不痛 提交于 2020-04-30 08:51:44
问题 I'm trying to call external_query with dynamically created query string in BigQuery Web UI. DECLARE extquery STRING; SET extquery = "SELECT * FROM mytable;"; SELECT * FROM EXTERNAL_QUERY("my-external-conn", extquery); This script gives an error Query error: Invalid table-valued function EXTERNAL_QUERY Connection argument in EXTERNAL_QUERY must be a literal string or query parameter Is it impossible to do in BigQuery? What is the right way to pass query as a parameter? 回答1: As error states -

External_query with dynamic query - Error: Connection argument in EXTERNAL_QUERY must be a literal string or query parameter

时光总嘲笑我的痴心妄想 提交于 2020-04-30 08:46:28
问题 I'm trying to call external_query with dynamically created query string in BigQuery Web UI. DECLARE extquery STRING; SET extquery = "SELECT * FROM mytable;"; SELECT * FROM EXTERNAL_QUERY("my-external-conn", extquery); This script gives an error Query error: Invalid table-valued function EXTERNAL_QUERY Connection argument in EXTERNAL_QUERY must be a literal string or query parameter Is it impossible to do in BigQuery? What is the right way to pass query as a parameter? 回答1: As error states -