I am not able to create temporary table in Bigquery - google-bigquery

got below error while trying to create temporary table in Bigquery .
create or replace temporary table mss.Business.test2 as
select * from mss.Business.registration
Query error: Temporary tables may not be qualified at [2:36]

As mentioned by #Jaytiger names are not included in the CREATE TEMP TABLE statement.
You can create temporary table to store the results of a query as follows:
CREATE OR REPLACE TEMP TABLE <table1> as (SELECT * FROM `<dataset>.<table2>`);
SELECT * from <table1>
You can follow this documentation for further examples on Temp tables.

Related

#temp table equivalent in Postgres?

In Sql Server, we can create temp table in sql editor like :
select * into #temp_sales_data from sales_data; -- this will create a temp table and insert data.
Please let us know what is the equivalent option in Postgres.
You just create one using create temp table
create temp table temp_sales_data
as
select *
from sales_data;

how to create a temp table in Dremio

I would like to create a temporary table as below in dremio
Select ABC into #temp_table
any advise?
I don't think DREMIO explicitly supports temporary tables. However, it does have the ability to create tables on the fly from the results of the query using create table as (CTAS):
create table temp_table as
select ABC;

How to registerTempTable in SparkSQL

Spark version:2.2.0.cloudera2
Usually, we register a temp table in this way:
dataframe.registerTempTable($table_name)
But if I want to create a table in SQL statement, like this:
CREATE TABLE test_table from select * from table1
Spark will create a permanent table. Is there some way to create a temp table in SparkSQL statement?
You need to add TEMPORARY keyword in the SQL statement which would restrict writing the records to hive metastore for that particular table.
CREATE TEMPORARY TABLE test_table from select * from table1
Refer: https://docs.databricks.com/spark/latest/spark-sql/language-manual/create-table.html

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.

How to copy a table schema with sql based on existance of the table?

I want to duplicate a table schema, but only if the target table does not yet exist:
CREATE TABLE IF NOT EXISTS my_table_secondary as select * from my_table_primary
Problem: running this if the my_secondary_table exists results in:
ERROR: Syntaxerror at "as".
What could I do to make this sql statement work?
(postgres 9.4)
To duplicate the schema of a table, you need a completely different syntax.
create table if not exists my_table_secondary (
like my_table_primary including all
);
INCLUDING ALL is an abbreviated form of INCLUDING DEFAULTS INCLUDING
CONSTRAINTS INCLUDING INDEXES INCLUDING STORAGE INCLUDING COMMENTS.
It doesn't duplicate foreign key constraints. See CREATE TABLE. Search for "The LIKE clause".
Try this approach:
CREATE OR REPLACE VIEW my_view AS SELECT * FROM my_table_primary;
CREATE TABLE IF NOT EXISTS my_table_secondary LIKE my_view;
INSERT INTO my_table_secondary
SELECT * FROM my_view
WHERE NOT EXISTS ( SELECT * FROM my_table_secondary );
More on CREATE TABLE ... LIKE: http://www.postgresql.org/docs/9.1/static/sql-createtable.html