pyodbc upsert error - SQL contains 0 parameter markers, but 3 parameters were supplied', 'HY000' - pyodbc

I am using pyodbc, impala driver for kudu on cloudera 5.16, Python 3.6.10 to do an upsert into kudu table. Insert works fine but upsert fails. I am getting an error: SQL contains 0 parameter markers, but 3 parameters were supplied', 'HY000' . The code looks like below:
import pyodbc
conn = pyodbc.connect('DSN=my-impala-dsn',autocommit=True)
crsr = conn.cursor()
crsr.execute("UPSERT INTO mydb.mytable (col1,col2,col3) values(?,?,?)", val1,val2,val3)
Any thoughts on the error?

Related

Access parquet files in Azure DataBricks by R via RODBC

I successfully configured connection to Azure DataBricks cluster and can query tables with
conn <- odbcConnect("AzureDatabricks")
sqlQuery(conn, "SELECT * FROM my_table")
but I need to access parquet files.
In Databricks I can do it with this code:
%sql
Select * FROM parquet.`/path/to/folder`
If I try this by R as
sqlQuery(conn, "Select * FROM parquet.`/path/to/folder`")
I receive error:
[Simba][SQLEngine] Table or view not found: SPARK.parquet./path/to/folder"
[RODBC] ERROR: Could not SQLExecDirect 'Select * FROM parquet.`/path/to/folder`
Is there way to access parquet files via RODBC?
You are experiencing this issue due to an error in your sql query itself. When you run Select * FROM parquet./path/to/folder, command you will not see table or view not found due to syntax error.
Example: Sample example for understanding the issue (when you run SELECT * FROM parquer.'somepath'), you will see the syntax error.
Note: After creating a Dataframe from parquet file, you have to register it as a temp table to run sql queries on it.
val sqlContext = new org.apache.spark.sql.SQLContext(sc)
val df = sqlContext.read.parquet("src/main/resources/peopleTwo.parquet")
df.printSchema
// after registering as a table you will be able to run sql queries
df.registerTempTable("people")
sqlContext.sql("select * from people").collect.foreach(println)
Reference: Spark SQL guide - Parquet files
You need to add UseNativeQuery=1; parameter to the odbc connection string.
Examlpe: Driver={Simba Spark ODBC Driver};Host=[serverHost];Port=443;HTTPPath=[httpPath];ThriftTransport=2;SSL=1;AuthMech=3;UID=token;PWD=[pwd];UseNativeQuery=1;
https://docs.databricks.com/integrations/jdbc-odbc-bi.html#ansi-sql-92-query-support-in-odbc

How to run pl/sql statements in Control M for database job/task(execution type :- Embedded Query)

I have pl/sql statement something like mentioned below, which executes successfully in oracle sql developer but same when am trying to execute through control M database task (execution type :- Embedded Query) am getting error "Invalid SQL statements"
SQL statements :-
TRUNCATE TABLE TEST;
COMMIT;
EXECUTE USP_LOADTESTTables;
COMMIT;
create a query file named plsql_query.ql then use it to execute from controlM as command line job.
Sqlcmd -E -server\instance_name -Q "EXEC plsql_query.ql"

\copy statement in PostgreSQL using R

I want to execute the following statement on postgresql sending it from R:
tname = 'foo'
con = some_connection_to_postgresql
q = paste("\\COPY", tname, "FROM 'foo.csv';")
dbGetQuery(con, q)
However, when I execute it, I get the following error:
Error: <SQL> '\COPY foo FROM 'foo.csv''
nanodbc/nanodbc.cpp:1587: 42601: ERROR: syntax error at or near "\";
Error while executing the query
However, the same script written from the terminal works perfectly fine.
\copy is not a postgresql statement. the psql CLI converts \copy...from filename into copy ... from stdin; and then pipes the file's contents over the postgres connection.
you'll have to do the same if you want to use copy.

Run Hive Query in R with Config

I'm able to successfully connect and run queries in R from Hive using library(DBI) and library(RJDBC)
However, I'm trying to set the following config
Set hive.execution.engine=mr;
When I try to use the following command (which is how I would query), I get an error:
dbGetQuery(conn_expp_team, "Set hive.execution.engine=mr")
Here is the error:
Error in .verify.JDBC.result(r, "Unable to retrieve JDBC result set for ", :
Unable to retrieve JDBC result set for Set hive.execution.engine=mr (The query did not generate a result set!)
Use RJDBC::dbSendUpdate(conn, statement). Source: https://github.com/s-u/RJDBC/issues/25

SAS connection to Teradata Database using Teradata ODBC

I'm trying to connect to Teradata in SAS. I set up an teradata ODBC on the machine. The assumption currently for me is that using ODBC is the only way for me to access the database. And here is the syntax of my connection command:
Libname Teradata ODBC dsn = 'dsnname' uid = 'uid' pwd = 'pwd';
results:
Error: The ODBC engine cannot be found.
Error: Error in the LIBNAME statement.
It keeps saying that the ODBC engine cannot be found. I'm really confused now. Is there anything wrong with the command? Or I have to do something else outside SAS?
I check the licence
Proc Setinit;
result:
SAS/ACCESS Interface to Teradata ** the date shows not expired.
Could anyone give me some idea. Thank you very much!
Can't say I've ever used ODBC to access Teradata, can see it being highly inefficient.
Normally, you'd do pass-thru SQL to Teradata...
proc sql ;
connect to teradata (user='username' pass='password' tdpid=prodserver) ;
create table mydata as
select * from connection to teradata
(select a.*
from ds.enterprise_table as a) ;
disconnect from teradata ;
quit ;
For a direct libname, the syntax would be
libname tdata teradata user='username' pass='password' tdpid=prodserver schema=ds ;
data mydata ;
set tdata.enterprise_table ;
run ;

Resources