Unable to determine schema of SELECT * in this query - google-bigquery

I have created a table in Bigquery using the data personsData.json and schema personsDataSchema.json provided by the documentation at https://developers.google.com/bigquery/docs/data#nested.
This query works fine:
SELECT children.* FROM dw_test.persons
But the following query gives the error Error: 0.0 - 0.0: Unable to determine schema of SELECT * in this query:
SELECT citiesLived.* FROM dw_test.persons
I understand that a workaround will be to simply list all the fields of citiesLived:
SELECT citiesLived.place, citiesLived.yearsLived FROM dw_test.persons
But in the case when the record has many fields, listing all the fields becomes cumbersome.
Could anyone please help?
Thank you so much.

Related

SQL: How to select data from column that does not end in 'EW'?

I have two identical tables on my web site, one table will show data where a certain column has a variable with the last letters are 'EW'. The code I am using for that is SELECT * FROM dry_mix WHERE note NOT LIKE '%EW';.
What I am trying to do now is fill my other table with data that does not end in 'EW'. I have tried the following code SELECT * FROM dry_mix WHERE note NOT LIKE '%EW'; but that is not working. Can anyone show me the correct way for me to write the code?
The correct syntax in most SQL variants would be:
SELECT * FROM dry_mix WHERE NOT(note LIKE '%EW');

DMV request for "Description" of the table for Power BI dataset

What I am trying to achieve is to add tables and columns descriptions programmatically to a Power BI dataset.
For this reason, I use Server Analysis Services to get access to the metadata.
I run a simple request:
select *
from $System.TMSCHEMA_PARTITIONS
As a result, I get a table with columns names:
ID
TableID
Name
Description
....
Now I want to select where the "Description" is empty.
select *
from $System.TMSCHEMA_PARTITIONS
where Description IS NULL
But I can't, I always get a syntax error:
Query (3, 7) The syntax for 'Description' is incorrect.
SQL reads it as a command and I don't know how to avoid it.
I have tried adding quotes and double quotes to the name of the columns, I tried adding a table reference and all of these combined, but nothing helps.
It works for "TableID" for example.
This one works:
select *
from $System.TMSCHEMA_PARTITIONS
where len([Description]) = 0

BigQuery - Resources error when I make a SELECT FIELD but no error when I do SELECT * (on the same table)

Working query: SELECT * FROM my_project.my_dataset.my_table
Not working query: SELECT id FROM my_project.my_dataset.my_table
Error I get: Resources exceeded during query execution: Not enough resources for query planning - too many subqueries or query is too complex.
I understand the error, but I don't understand why it's occuring when I change '*' to any field (id for exemple)
thank you :)

BigQuery: how to convert this legacy SQL to standardSQL?

I have data import pipeline into BigQuery tables (the hourly tables named transactions_20170616_00 transactions_20170616_01 ... and there are more daily/weekly/... rollups), want to use a single view to always point to the latest one, found hard to do one static standardSQL view to point to latest, my current solution is to update the view's content to SELECT * FROM project.dataset.transactions_201706.... after every import successful,
Till I read this httparchive's latest view: it's all what I want but in legacy SQL; my project uses all standardSQL only, and prefer standardSQL because it's the future; wonder anyone knows how to convert this legacy SQL to standardSQL? then I won't need to constantly update my view
https://bigquery.cloud.google.com/table/httparchive:runs.latest_requests?tab=details
SELECT *
FROM TABLE_QUERY(httparchive:runs,
"table_id IN (
SELECT table_id FROM [httparchive:runs.__TABLES__]
WHERE REGEXP_MATCH(table_id, '2.*requests$')
ORDER BY table_id DESC LIMIT 1)")
following this guide, I'm trying to use
https://cloud.google.com/bigquery/docs/querying-wildcard-tables#the_table_query_function
#standardSQL
SELECT * FROM `httparchive.runs.*`
WHERE _TABLE_SUFFIX IN
( SELECT table_id
FROM httparchive.runs.__TABLES__
WHERE REGEXP_CONTAINS(table_id, r'2.*requests$')
ORDER BY table_id DESC
LIMIT 1)
but the query failed of
Query Failed
Error: Views cannot be queried through prefix. Matched views are: httparchive:runs.latest_pages, httparchive:runs.latest_pages_mobile, httparchive:runs.latest_requests, httparchive:runs.latest_requests_mobile
Job ID: bidder-1183:bquijob_1400109e_15cb1dc3c0c
I found the wildcard can only be used at last? in this case why not SELECT * FROM httparchive.runs.*_requests WHERE ... work?
in this case, is it saying the Wildcard Tables feature in standardSQL isn't same flexible as TABLE_QUERY in legacySQL>?

Unable to select data locally

Right, so when I run:
Select * from Consultants
I get:
ORA-00942: table or view does not exist
The table clearly exists in the object browser.
However, when I run:
select * from Customers#xe.m512Finn
I get the data requested.
Please don't tell me that the table in the local database doesn't exist because it does; I created it and it's there in the object browser.
Is there something wrong with my syntax? Please help me with any suggestions.
Here you're selecting from the Consultants table
Select * from Consultants
And here you're selecting from the Customers table
select * from Customers#xe.m512Finn
The table does exists in m512Finn user that's why it returns the values for
select * from Customers#xe.m512Finn
You might be running that query in a different schema or the query u might be looking for must be
Select * from consultants#xe.m512Finn
Okay i've resolved the issue, it's that when you query local tables, you need double quotation marks around the table name.
select * from "Consultants"