Support Questions
Find answers, ask questions, and share your expertise

type casting string variable to varchar2

Contributor

Hello

 

I am writing a code to Oracle to Impala data mirroring with python.

I am using cx_Oracle for Oracle connection and impyla for Impala connections.I have created Impala tables' fields with similar type of Oracle tables' fields

 

I am reading varchar2 type variable from Oracle without any error but could not insert it into Impala as string. So I try to insert like following statement

 

sql = "insert into test01.testdcr values (%f, cast('%s' as VARCHAR(128)), %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, '%s')" % \
			   (row[0], row[1], row[3], row[4], row[5], row[6], row[7], row[8], row[9], row[10], row[11], row[12], row[2])
curImpala.execute (sql)

There was no error in above code so I could successfully insert my data

 

But there is a note in Impala documentation about string data type

 

 You can use CAST() to convert STRING values to TINYINT, SMALLINT, INT, BIGINT, FLOAT, DOUBLE, or TIMESTAMP.

 

 

So there is no VARCHAR type conversion from STRING.

 

My question is can I trust my code ?

If not what is the proper way of this conversion ?

 

Best regards

 

 

 

1 REPLY 1

The list of conversions isn't exhaustive. The Varchar docs for Impala 2.0.x have examples for the conversion you're looking for:

 

http://www.cloudera.com/content/www/en-us/documentation/enterprise/5-2-x/topics/impala_varchar.html