I'm trying to bring together the events recorded on firebase for android and ios, but when I try to perform an union on the tables, I get:
Error: Duplicate column names in the result are not supported. Found duplicate(s): user_dim, event_dim
My query (standardSQL):
SELECT
*
FROM
`com_myapp_ANDROID.app_events_*`,
`com_myapp_IOS.app_events_*`
I can select the fields independently and create aliases, but then I won't have a real merge why I would like to import into google data studio
Try below
#standardSQL
SELECT * FROM `com_myapp_ANDROID.app_events_*`
UNION ALL
SELECT * FROM `com_myapp_IOS.app_events_*`
LIMIT 11
comma as a UNION works only in BigQuery Legacy SQL - comma is treated as CROSS JOIN in BigQuery Standard SQL
In BigQuery Standard SQL you must use UNION explicitly
Related
The below crashes my DB Browser. Essentially I am trying to sum sales ("sales") by a sales person ("name") that occurred between two dates ("beg_period" and "end_period") pulled from a separate table.
SELECT ta.name, ta.beg_period, ta.end_period,
(SELECT SUM(tb.sales)
FROM sales_log tb
WHERE ta.name = tb.name
AND tb.date BETWEEN ta.beg_period AND ta.end_period
)
FROM performance ta
;
The nested query can be re-written as a single query with a standard join.
SELECT ta.name, ta.beg_period, ta.end_period, SUM(tb.sales)
FROM performance ta INNER JOIN sales_log tb
ON ta.name = tb.name
WHERE tb.date BETWEEN ta.beg_period AND ta.end_period
GROUP BY ta.name, ta.beg_period, ta.end_period;
My guess is that the original query was okay (however inefficient), but DB Browser just didn't know how to interpret the subquery for whatever parsing it attempts, etc. In other words, just because it crashed DB Browser doesn't mean that it would crash sqlite library. Try another sqlite database manager.
I already link the firebase to bigquery, and everyday a new table gets created with the date stamp. The columns within the export can be found in the following link: https://support.google.com/firebase/answer/7029846?hl=en
BUT, there is not firebase analytics data(such as add_porduct_like, add_product_to_cart, and so on) being export. how can I export complete data into BigQuery.
Firebase Analytics data is already exported in those daily tables formed each day in Big Query.
What is required over here is to run queries in order to extract the relevant data.
Take a look at this doc for sample queries when Firebase Data is exported to Big Query.
In short, you need to make use of the schema and based on the Field Name, you can query the data obtained in Big Query by Firebase.
When you submit an event with parameters to Firebase Analytics, it is stored as an array in the column event_dim.params.
To get data from database, you will need to use this query (I'm using standard SQL):
SELECT
event_dim.name AS event_name,
event_dim.params AS event_params
FROM
`project.your_app.app_events_20171109`,
UNNEST(event_dim) as event_dim
If you want to get specific parameter, you'll also have to unnest another field:
SELECT
event_dim.name AS event_name,
event_dim.params AS event_params
FROM
`project.your_app.app_events_20171109`,
UNNEST(event_dim) as event_dim,
UNNEST(event_dim.params) as params
WHERE params.key LIKE "add_product_to_cart"
You can read more about how Firebase Analytics stores data and how to use UNNEST function here: https://firebase.googleblog.com/2017/03/bigquery-tip-unnest-function.html
I have a table with
zip_client zip_supplier zip_store
12345 56432 42374
35424 null 12345
etc
And I need to get overall unique zips.
Is there a simple way to do it within a query?
Currently I download the result into Sheets and do it there.
If there was some kind of reshape in BigQuery it would be very easy, but I could not find how to do it.
Thanks
Below is for BigQuery Legacy SQL
#legacySQL
SELECT
type, zip
FROM
(SELECT 'client' AS type, zip_client AS zip FROM yourTable),
(SELECT 'supplier' AS type, zip_supplier AS zip FROM yourTable),
(SELECT 'store' AS type, zip_store AS zip FROM yourTable)
WHERE NOT zip IS NULL
if you will have chance or decide to migrate to BigQuery Standard SQL - see below
#standardSQL
SELECT zip.type, zip.zip
FROM yourTable,
UNNEST([STRUCT<type STRING, zip INT64>
('client', zip_client),
('supplier', zip_supplier),
('store', zip_store)]) AS zip
WHERE NOT zip.zip IS NULL
Using standard SQL:
SELECT DISTINCT zip
FROM YourTable
CROSS JOIN UNNEST([zip_client, zip_supplier, zip_store]) AS zip;
You can put any number of columns inside the UNNEST depending on the structure of your table.
I saved it to Big Query with Firebase Analytics.
I want to SELECT the events stored in the big query. But the tables are by date.
Is there anyway to SELECT events on these tables at once?
Check Wildcard Tables feature
Quick example:
#standardSQL
SELECT *
FROM `project.dataset.app_events_*`
I have two sqlite3 databases which have tables with identical schemas and (possibly) overlapping data. For example a Temperature table in both databases. If I want to get all the columns from both tables combined I will first ATTACH the other database:
sqlite> ATTACH DATABASE 'old.sqlite' AS Old;
and then combine them with UNION like this:
sqlite> SELECT * FROM Temperature UNION SELECT * FROM Old.Temperature;
This works fine.
However sometimes there is just one table. For example for humidity I might have just one Humidity and no counterpart in the other database. In this case the query fails:
sqlite> SELECT * FROM Humidity UNION SELECT * FROM Old.Humidity;
SQL error: no such table: Old.Humidity
What I would like to get is all columns from the tables that do exist and not to fail just because the other table doesn't exist.
I don't know before hand which tables exist in which databases. I only have the table names from all the databases combined into one list. And the part of the codebase that's reading the data expects to get all the columns in one query.
It is not possible to create a query dyncamically in SQL.
(SQLite is designed to be used from within an application written in a 'real' programming language.)
You have to check beforehand whether the table exists (use PRAGMA table_info, or try if a query using that table works).
Then execute a query either with or without UNION.