1

I have varchar2 fields in my databases (Oracle and Impala) and I want to insert string fields into this fields. I could not insert the values as string as normally. I got following error

AnalysisException: Possible loss of precision for target table 'test01.testdcr'. Expression ''data1 data2 data3 data4 '' (type: STRING) would need to be cast to VARCHAR(128) for column 'testVarchar2Field'

How can I convert string variable to varchar2 while inserting into table ?

1 Answers1

2

From the documentations, there is a cast function that works like:

select concat('Here are the first ',10,' results.'); -- Fails
select concat('Here are the first ',cast(10 as string),' results.'); -- Succeeds

They also state somewhere else this other example:

When you insert the results of an expression, particularly of a built-in function call, into a small numeric column such as INT, SMALLINT, TINYINT, or FLOAT, you might need to use a CAST() expression to coerce values into the appropriate type. Impala does not automatically convert from a larger type to a smaller one. For example, to insert cosine values into a FLOAT column, write CAST(COS(angle) AS FLOAT) in the INSERT statement to make the conversion explicit.

Doesn't it solve your problem?

Nikign
  • 379
  • 3
  • 9