Reputation: 2378
I'm trying to use Talend to get JSON data that is stored in MySQL as a VARCHAR datatype and export it into PostgreSQL 9.4 table of the following type:
CREATE TABLE myTable( myJSON as JSONB)
When I try running the job I get the following error:
ERROR: column "json_string" is of type json but expression is of type character varying
Hint: You will need to rewrite or cast the expression. Position: 54
If I use python or just plain SQL with PostgreSQL insert I can insert a string such as '{"Name":"blah"}' and it understands it.
INSERT INTO myTable(myJSON) VALUES ('{"Name":"blah"}');
Any Idea's how this can be done in Talend?
Upvotes: 3
Views: 4478
Reputation: 2759
Here is a sample schema for where in i have the input row 'r' which has question_json and choice_json columns which are json strings. From which i know the key what i wanted to extract and here is how i do
you should look at the columns question_value and choice_value. Hope this helps you
Upvotes: 0
Reputation: 21697
You can add a type-cast by opening the "Advanced Settings" tab on you "tPostgresqlOutput" component. Consider the following example:
In this case, the input row to "tPostgresqlOutput_1" has one column data
. This column is of type String
and is mapped to the database column data
of type VARCHAR
(as by the default suggested by Talend):
Next, open the component settings for tPostgresqlOutput_1
and locate the "Advanced settings" tab:
On this tab, you can replace the existing data
column by a new expression:
"?::json"`. Note the usage of the placeholder character
?`` which will be replaced with the original value.Replace
. This will replace the value proposed by Talend with your SQL expression (including the type cast).This should do the trick.
Upvotes: 7