Talend - tOralcerow Issue - talend

Team, I'm using the below insert query to insert data into a table. But I'm getting syntax error not sure what I'm missing here,
insert into employee (emp_id,dept_id,emp_nm,emp_address,insert_date)
values(#EMP_ID,(select max(dept_id) + 1 as dept_id from
department),#EMP_NM,NULL,to_char(sysdate(),”DD-MM-YYYY”))
Getting error as “tOraclerow - ORA-00936 missing expression” Please help on this issue.
Basically i'm getting the columns in the flow till the tOracelrow component, I need to know what is the coding or procedure on how to access the same in the query written inside the tOraclerow component.

At the place of #EMP_ID, please use your flowname.EMP_ID
for example : row1.EMP_ID
if your column is string than put this variable in quote also like
"insert into employee (emp_id,dept_id,emp_nm,emp_address,insert_date)
values("+row1.EMP_ID+",(select max(dept_id) + 1 as dept_id from
department),'"+row1.EMP_ID+"',NULL,to_char(sysdate(),”DD-MM-YYYY”))"
Hope this helps..

Related

Sequelize how to use aggregate function on Postgres JSONB column

I have created one table with JSONB column as "data"
And the sample value of that column is
[{field_id:1, value:10},{field_id:2, value:"some string"}]
Now there are multiple rows like this..
What i want ?
I want to use aggregate function on "data" column such that, i should
get
Sum of all value where field_id = 1;
Avg of value where field_id = 1;
I have searched alot on google but not able to find a proper solution.
sometimes it says "Field doesn't exist" and some times it says "from clause missing"
I tried referring like data.value & also data -> value lastly data ->> value
But nothing is working.
Please let me know the solution if any one knows,
Thanks in advance.
Your attributes should be something like this, so you instruct it to run the function on a specific value:
attributes: [
[sequelize.fn('sum', sequelize.literal("data->>'value'")), 'json_sum'],
[sequelize.fn('avg', sequelize.literal("data->>'value'")), 'json_avg']
]
Then in WHERE, you reference field_id in a similar way, using literal():
where: sequelize.literal("data->>'field_id' = 1")
Your example also included a string for the value of "value" which of course won't work. But if the basic Sequelize setup works on a good set of data, you can enhance the WHERE clause to test for numeric "value" data, there are good examples here: Postgres query to check a string is a number
Hopefully this gets you close. In my experience with Sequelize + Postgres, it helps to run the program in such a way that you see what queries it creates, like in a terminal where the output is streaming. On the way to a working statement, you'll either create objects which Sequelize doesn't like, or Sequelize will create bad queries which Postgres doesn't like. If the query looks close, take it into pgAdmin for further work, then try to reproduce your adjustments in Sequelize. Good luck!

Correct syntax for inserting Date values via Insert command in EF's ExecuteStoreCommand

I am using EF6 with SQL Server/SQL Azure with C# and MVC5
I am trying to do something like:
string insertFeatureCmd = String.Format("INSERT INTO TABLE (Name,Value, DateActivated) " + "VALUES ('{0}','{1}','{2}')", name,value, DateTime.Now);
db.ExecuteStoreCommand(insertFeatureCmd);
What is the correct syntax for handling the Date Value? Is it '{2}' or {2}. Also do I need to do something with DateTime.Now ie DateTime.Now.ToString() or "DateTime.Now.ToLongDateString()" or something?
Thanks.
EDIT
I get the following SQL generated from my C#. Question is what to do with that data value?
INSERT INTO TABLE (Name,Value,DateActivated) VALUES ('Name','Value',07/04/2019 02:39:24)
EDIT2
This does not work. I get an exception:
INSERT INTO TABLE (Name,Value,DateActivated) VALUES ('Name','Value','07/04/2019 02:39:24')
EDIT3: In response to suggested alternative answer. My solution that I went with was, inspired by link, but was:
new SqlParameter("#sinceDateTime", myDate)

Updating the table through tOracleOutput in Talend using an additional SQL query

I have a job where I am getting a flow into tOracleOutput where I am updating the table. Now, I have to update that table using an SQL statement, which I guess we have option in Advanced settings of tOracleOuptut, but I don't know how to use it or you can say that I am not getting the settings properly. I referred to official documentation but could not understand. Can any one explain the fields like Name, SQL expression, Position, Reference Column in a better way?
the SQL query which I am using is:
update set COL1=SOMETHING1
where COL2=SOMETHING2
Now, value for COL1 is coming from the flow but COL2 is some column in the table which is not coming from the flow.
Have a look to tOracleRow for such a case.
Hope this helps.
TRF
Using tOracleOutput is helpful when a ready data source (table or file (...) with same columns as destination) the more elaborate your query is, the more you should do as TRF said (and use tOracleRow), but here's an example to your question:
file contain 3 column,
DB table of destination contains 4 column, where the 4th is the date of update, (the first 3 are identical to the input)
so you add the destination's column's name in Name and put the SQL function for the date (eg: SYSDATE) and where to put it (Position) in reference to a column of your choice (Reference Column)
In my view it helps avoid using tMap for a miserable additional column when you want to Insert, but you want to Update, in which case the component doesn't offer the additional column section, plus I don't think you can add the WHERE clause here
Hope it helps

Insert yyyyMMdd string into date column using Talend

I have the follow situation:
A PostgreSQL database with a table that contains a date type column called date.
A string from a delimited .txt file outputting: 20170101.
I want to insert the string into the date type column.
So far i have tried the following with mixed results/errors:
row1.YYYYMMDD
Detail Message: Type mismatch: cannot convert from String to Date
Explanation: This one is fairly obvious.
TalendDate.parseDate("yyyyMMdd",row1.YYYYMMDD)
Batch entry 0 INSERT INTO "data" ("location_id","date","avg_winddirection","avg_windspeed","avg_temperature","min_temperature","max_temperature","total_hours_sun","avg_precipitation") VALUES (209,2017-01-01 00:00:00.000000 +01:00:00,207,7.7,NULL,NULL,NULL,NULL,NULL) was aborted. Call getNextException to see the cause.
can see the string parsed into "2017-01-01 00:00:00.000000 +01:00:00".
When I try to execute the query directly i get a "SQL Error: 42601: ERROR: Syntax error at "00" position 194"
Other observations/attempts:
The funny thing is if I use '20170101' as a string in the query it works, see below.
INSERT INTO "data" ("location_id","date","avg_winddirection","avg_windspeed","avg_temperature","min_temperature","max_temperature","total_hours_sun","avg_precipitation") VALUES (209,'20170101',207,7.7,NULL,NULL,NULL,NULL,NULL)
I've also tried to change the schema of the database date column to string. It produces the following:
Batch entry 0 INSERT INTO "data" ("location_id","date","avg_winddirection","avg_windspeed","avg_temperature","min_temperature","max_temperature","total_hours_sun","avg_precipitation") VALUES (209,20170101,207,7.7,NULL,NULL,NULL,NULL,NULL) was aborted. Call getNextException to see the cause.
This query also doesn't work directly because the date isn't between single quotes.
What am i missing or not doing?
(I've started learning to use Talend 2-3 days ago)
EDIT//
Screenshots of my Job and tMap
http://imgur.com/a/kSFd0
EDIT//It doesnt appear to be a date formatting problem but a Talend to PostgreSQL connection problem
EDIT//
FIXED: It was a stupid easy problem/solution ofcourse. THe database name and schema name fields were empty... so it basically didnt know where to connect
You don't have to do anything to insert a string like 20170101 into a date column. PostgreSQL will handle it for you it's just ISO 8601's date format.
CREATE TABLE foo ( x date );
INSERT INTO foo (x) VALUES ( '20170101' );
This is just a talend problem, if anything.
[..] (209,2017-01-01 00:00:00.000000 +01:00:00,207,7.7,NULL,NULL,NULL,NULL,NULL)[..]
If Talend doesn't know by itself that passing timestamp into query requires it to be single quoted, then if possible - you need to do it.
FIXED: It was a stupid easy problem/solution ofcourse. THe database name and schema name fields were empty... so it basically didnt know where to connect thats why i got the BATCH 0 error and when i went deeper while debugging i found it couldnt find the table, stating the relation didnt exist.
Try like this,
The data in input file is: 20170101(in String format)
then set the tMap like,
The output is as follows:

MySQLi Update data in a table

Please help me out with this. Basically to update an existing table (chem_users) with data using 2 keys UserId & Password (or only 1 primary key is allowed?).
Using MySQLi, what is wrong with this syntax.
$sql = "UPDATE chem_users SET (Prj1, Prj2) VALUES ('{$_POST['kinetics']}',
'{$_POST['thermo']}') WHERE (UserId=JohnKing Password=1234rewq)";
I got this error:
Error saving user data You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(Prj1, Prj2) VALUES ('kinetics' at line 1
Try using this syntax:
$sql="UPDATE `chem_users` SET `Prj1`=".$_POST['kinetics'].",`Prj2`=".$_POST['thermo']." WHERE `UserId`='JohnKing' AND `Password`='1234rewq'";
By the way, you shouldn't just concatenate a variable inside a query like you are doing,you should use Prepared Statements.You can learn a little bit about it in this link: http://www.w3schools.com/php/php_mysql_prepared_statements.asp