Forming insert into query using rimpala in R - sql

I am trying to execute insert into query on impala table using rimpala.query() function through R but I am getting an error. The query that I am executing is:
for(x in nrow)
{
rite <- paste("INSERT INTO table1 (account_no, data_id, date_id, industry_no, sales_no, sales) VALUES (1445367,",data_frame1$data_id[x] ,",25,11346,23,", data_frame1$sales[x], ")",sep="")
sql <- rimpala.query(rite);
}
where data_frame1 is the data frame which has bunch of rows and nrow is the number of rows in data_frame1. The first insert into statement executes and fist data is inserted into database but it throws an error just after executing that as
Error in rimpala.query(sql) : SQL error Error: The query did not generate a result set!
How do I remove this error?

The error is in the RImpala client, which is using executeQuery to run all queries, even those that modify state. They should be using executeUpdate for DDL and INSERT, UPDATE, or DELETE queries. I've filed an issue upstream for you.

Related

dbGetQuery() Error: Can't retrieve the table or table data using SQL in R

I am trying to use the SQL query to count the number of rows of myid in Table_1 data frame. The data frame is already present in R Environment and I retrieved it by following query.
Table_1 <- dbGetQuery(conn, "Select * FROM Patients") .
Now to count() the number of rows of myid in Table_1, I use following query and it says
count_myid <- dbGetQuery(conn, "Select count(myid) FROM Table_1")
Invalid object name 'Table_1'[Microsoft][odbc sql server driver]
[sql server] Statement(s) could not be prepared
Whereas, I checked the above mentioned query for another Table and it works perfectly fine for another table. I spent hours on this to figure out the problem but I couldn't that what is actually wrong in this query and why its not working. I know it can be done using different functions of R. I did used dbReadTable() and all the same queries mentioned in this Question, but not working.
If I try to retrieve it directly from SQL database and not from the R Environment, then it works fine. From SQL DB, I use the following query.
count_myid <- dbGetQuery(conn, "Select count(myid) FROM MyProj.dbo.Patients")

Error in using with statement with PostgreSQL insert query

I am trying to use a with clause with postgres insert statement
with inserted_record as (insert into person_age(person_name, years_old) values ('asnim', 21) returning *);
However, it errors out like
SQL Error [42601]: ERROR: syntax error at end of input
Position: 108
If i run it with without the the with clause it works
insert into person_age(person_name, years_old) values ('asnim', 21) returning *;
What am I missing here?
A CTE (WITH clause) is part of an SQL statement and cannot stand on its own. PostgreSQL complains about an error at the end of the statement, because it expects a following SELECT, INSERT, UPDATE or DELETE.
In a way, a CTE is like a view defined only for a single statement. You cannot define a CTE and then use it with several statements; for that, you could define a temporary view in the pg_temp schema.

Sybase interacting with mybatis

Im unable to insert multiple records in a single transaction. Im using foreach in mapper and I'm getting incorrect syntax near ','.
I googled and found, in sybase it's not possible to insert multiple rows in sybase.
Insert statement looks like:
insert into Student(id,name)
values (1, Jon), (2,mike),(3,sam)
Comma next to value statement, is creating issue.

Running Insert query in SSIS Package

I'm new to SSIS packages. I have to run a INSERT query which will be result on an SELECT query.
1) I will run the select query using ODBC source and it will return 6 columns and one of them will be the INSERT query.
I tried putting the query in Flat file destination(.sql extension) it comes out to be fine but cannot fetch it I don't know why might be because of it is dynamic insert query.
Can anyone help me how can I do that?
From your SELECT query, store the value of the column containing the INSERT query in a package variable. Then for your INSERT query, choose the "query from variable" option and use the variable as the source.
This tutorial shows how to store the result of a select query in a variable.

Update multiple values in an oracle table using values from an APEX collection

I am using APEX collections to store some values and pass them between pages in Oracle Application Express 4.2.3.
I would like to then perform an update statement on a table called "project" with the values from the collection.
My code so far is as follows:
update project
SET name=c.c002,
description=c.c007,
start_date=c.c004,
timeframe=c.c005,
status=c.c009
FROM
apex_collections c
WHERE
c.collection_name = 'PROJECT_DETAILS_COLLECTION'
and id = :p14_id;
where :p14_id is the value of a page item.
However, I am getting the following error:
ORA-00933: SQL command not properly ended
Anyone have any idea on how to approach this?
Thanks!
The UPDATE syntax you are using is not valid in Oracle; it does not allow you to use FROM in the way you are attempting.
The simplest way to do this in Oracle would with a subquery:
update project
set (name, description, start_date, timeframe, status) =
(select c.c002, c.c007, c.c004, c.c005, c.c009
FROM
apex_collections c
WHERE
c.collection_name = 'PROJECT_DETAILS_COLLECTION'
)
WHERE
id = :p14_id
;
Note that if the subquery returns no rows, the columns in the target table will be updated to NULL; this could be avoided by adding a similar EXISTS condition in the predicate for the update. It could also be avoided by using a MERGE statement instead of an UPDATE.
If the subquery returns multiple rows, the statement will throw an error. It looks like tthat should not be the case here.