Insert into postgres table using apache drill - apache-drill

Is it possible to insert data into an existing table in postgres database using apache drill.something similar to
insert into Post_db.test_schema.customer_account_holder_test select customer_id,source_system_id,salutation,first_name,middle_name,last_name,legal_name,gender,identity_proof_name,identity_proof_value from hive.schema_name.customer_account_holder limit 10

In apache drill, Insert is not supported.
You can creates a new table and populates the new table with rows returned from a SELECT query. Use the CREATE TABLE AS (CTAS) statement in place of INSERT INTO. CREATE TABLE name AS query;

Related

How to insert values into temp table while executing query

I am using laravel framework for developing APIS , i have a challenging situation while executing my current query at that time i have to create temporary table with some columns and i have to insert some data based on current running query column values,can anyone please give me some idea how to acheive this one?
$q = user::query();
//some joins and where conditions stuff is there here
$q->addselect(“col1 as UserName”)
if($data[“name”]==“test”){
DB::statement('CREATE TEMPORARY TABLE temp SELECT ...i want to insert UserName value here in my temp table column called tempCol');
}
$q->paginate();

INSERT & UPDATE MySql table using PySpark DataFrames and JDBC

I'm trying to insert and update some data on MySql using PySpark SQL DataFrames and JDBC connection.
I've succeeded to insert new data using the SaveMode.Append. Is there a way to update the existing data and insert new data in MySql Table from PySpark SQL?
My code to insert is:
myDataFrame.write.mode(SaveMode.Append).jdbc(JDBCurl,mySqlTable,connectionProperties)
If I change to SaveMode.Overwrite it deletes the full table and creates a new one, I'm looking for something like the "ON DUPLICATE KEY UPDATE" available in MySql
Any help on this is highly appreciated.
Create a view in Mysql as create view <viewName> as select ...<tableName>
Create trigger in mysql to update after insert using -
CREATE TRIGGER trigger_name
AFTER INSERT
ON <viewName> FOR EACH ROW
BEGIN
-- statements
-- INSERT ... ON DUPLICATE KEY UPDATE Statement
END$$
ref - https://www.mysqltutorial.org/mysql-triggers/mysql-after-insert-trigger/
Write data to view <viewName> from spark

How to select content from a table into a new table in SQL stored procedures?

I was trying to write a procedure and needed to copy output_1 table into a new one.
This procedure :
BEGIN
SELECT * INTO newtable FROM output_1;
END
returns the following error :Undeclared variable: newtable
I thought it would create a new table and all its columns automatically.
How do I SELECT multiple columns of a table INTO a new table using a stored procedure?
EDIT :
In stored procedures, when you want to use a table to store data temporarily, you should consider using temporary tables.
Typically, if you try to store a table in a variable, you will get a multiple rows error ; in this case, temporary tables can replace variables.
CREATE TEMPORARY TABLE new_table AS SELECT * FROM output_1;
You cannot select into a table. You possibly intended
create table newtable as select * from output_1;
https://dev.mysql.com/doc/refman/8.0/en/create-table-select.html

Is it possible to insert data from MySQL table to MSAccess Table using SQL Query?

I want to insert data from my MySQL table to ms-access table using query.
So is it possible.
I am using vb 6 and MySQL and ms-access databases both.
Yes, it can be done. You need to
install MySQL Connector/ODBC,
create an ODBC "System DSN" for the MySQL database, and then
create an ODBC Linked Table in Access that points to the MySQL table
Once that is done you can insert data from the MySQL table into an Access table with a statement like
INSERT INTO accesstable (field1, field2)
SELECT column1, column2 FROM linkedtable;

Use of SELECT INTO

Is it necessary to define the new table definition before using SELECT INTO query in MYSQL.
I am getting problem to execute the query when I writ e like:
SELECT *
INTO newtable
FROM oldtable
WHERE 1=0;
the error showing is:
Undeclared variabie: newtable
if you have newtable
try :
INSERT INTO newtable SELECT ...
if you don't have newtable
try :
CREATE TABLE newtable AS SELECT ...
The MySQL manual search engine is terrible but googling for something like mysql 5.5 select into will normally take you to the right page:
MySQL Server doesn't support the SELECT ... INTO TABLE Sybase SQL
extension. Instead, MySQL Server supports the INSERT INTO ... SELECT
standard SQL syntax, which is basically the same thing.
If you read the documentation here it says:
With INSERT ... SELECT, you can quickly insert many rows into a table from one or many tables
So, yes, you need to create the new table first.
You can use CREATE TABLE new LIKE old to create a new, empty table, which is a copy of the original table structure.