Schedule query on bigquery - cant create schedule query with the table get external data from googlesheet - sql

I've create the bigquery table with the name 'table_a', which was get data from google sheet. I cant you this table directly to use on other service, and I want to create schedule query to create new table
select * from table_a => table_b
but there was some problem when I scheduled this query:
Error code 3 : Invalid value: table_a is not allowed for this operation because it is currently a EXTERNAL.
I need your help on this, how can I create a table_b from table_a.
Many thanks

Related

Teradata query using a large list of values in WHERE predicate

I'm attempting to query Teradata in SQL Assistant, something along the lines of
select * from
addressTable
where accountNumber in
(
'AC001',
'AC098',
'AC711',
...
)
from a list of over 100,000 accountNumbers sent to me in a file.
What I have tried
StackOverflow past questions - all seem to say that you need to insert into a temp table using a select clause from a table within the same database
Teradata doco on the link below. When I go to create table globdb.gt1, I get error 'CREATE TABLE Failed 3802: Database 'globdb' does not exist.
https://docs.teradata.com/r/Teradata-Database-SQL-Fundamentals/June-2017/Database-Objects/Tables/Global-Temporary-Tables

Using a select statement to define a table name

I am trying to create snapshot tables as part of script I run regularly.
At the moment I have to manually enter table names, but I would like to call on a field in the base data table to create the snapshot table name.
For example:
Base Data Table = base_data and contains a field for the month it was created in.
Snapshot table = base_data_month
I have already tried to run this to create an automatically named table...
create table base_data_snapshot_||(select month from base_data) as
select * from base_data
But this gets a syntax error. For reference there is only one month included in the base data.
Has anyone had any success with this before?
Although we cant combine a running create statement with a select but can use select. So, I guess below should work
create table
base_data_snapshot_||t.month
as
( select * from base_data) t

'Create Table As' in BigQuery

How to create a table on the basis of result of select query in BigQuery?
For example:
create table abc as select x,y,z from mnp;
Is there any way or workaround to achieve the same in BigQuery?
Any leads?
Just try giving the GCP dataset name before table name in create table statement.
Example:
create table `GCP_Dataset.abc` as select x,y,z from mnp
CREATE OR REPLACE TABLE [GCP_Folder].abc AS SELECT x,y,z FROM mnp
This wont get the error Cannot set write disposition in jobs with DDL statements. no source to refer, its trial and error from my end.
already it can be done like
CREATE OR REPLACE TABLE project.dataset.table AS SELECT x,y,z FROM 'project.dataset.mnp'
You can create a table using another table as the starting point.
This method basically allows you to duplicate another table (or a part
of it, if you add a WHERE clause in the SELECT statement).
CREATE TABLE project_name.dataset_name.table (your destination) AS SELECT column_a,column_b,... FROM (UNION/JOIN for example)

How to copy table by spark-sql

Actually, I want to move one table to another database.
But spark don't permit this.
Then, how to copy table by spark-sql?
I already tried this.
SELECT *
INTO table1 IN new_database
FROM old_database.table1
But it was not working.
maybe try:
CREATE TABLE new_db.new_table AS
SELECT *
FROM old_db.old_table;
To preserve partitioning and storage format do the following-
Get the complete schema of the existing table by running-
show create table db.old_table
The above query will output the table schema which you can just execute after changing the path name and table name.
Then insert all the rows into the new blank table using-
insert into db.new_table select * from db.old_table
The following snippet will create a new table while preserving the definition of the "old" table.
CREATE TABLE db.new_table LIKE db.old_table;
For more info, check the doc's CREATE TABLE.

Create external table with select from other table

I am using HDInsight and need to delete my clusters when I am finished running queries. However, I need the data I gather to survive for another day. I am working on queries that would create calculated columns from table1 and insert them into table2. First I wanted a simple test to copy the rows. Can you create an external table from a select statement?
drop table if exists table2;
create external table table2 as
select *
from table1
STORED AS TEXTFILE LOCATION 'wasb://{container name}#{storage name}.blob.core.windows.net/';
yes but you have to seperate it into two commands. First create the external table then fill it.
create external table table2(attribute STRING)
STORED AS TEXTFILE
LOCATION 'table2';
INSERT OVERWRITE TABLE table2 Select * from table1;
The schema of table2 has to be the same as the select query, in this example it consists only of one string attribute.
I know this is too stale question but here is the solution.
CREATE EXTERNAL TABLE table2
STORED AS textfile
LOCATION wasb://....
AS SELECT * FROM table1
Since create external table with "as select" clause is not supported in Hive, first we need to create external table with complete DDL command and then load the data into the table. Please go through this for different data format supports.
create external table table_ext(col1 typ1,...)
STORED AS ORC
LOCATION 'table2'; // optional if not provided then default location is used
INSERT OVERWRITE TABLE table_ext Select * from table1;
make sure table_ext has same DDL as table1.