likeGreen
likeGreen

Reputation: 1079

Nifi PutDatabaseRecord to update a table with where condition

How to use PutDatabaseRecord to UPDATE only three columns of a table named student having several columns? I am trying to achieve following query with where clause using NiFi.

update student set class=v1,name=v2,section=v3 where 
id = v4

I am getting the values v1,v2,v3,v4 using ExecuteSQL processor. There can be 100 of students registered on the same date. So, v1,v2,v3,v4 will be array of json

 SELECT class,name,section,id
    FROM registration where registerd_on='20210530';

enter image description here

My PutDatabaseRecord config. I want to understand how to specify where condition here?

enter image description here

Upvotes: 1

Views: 4544

Answers (1)

daggett
daggett

Reputation: 28564

according to documentation

https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-standard-nar/1.14.0/org.apache.nifi.processors.standard.PutDatabaseRecord/

Update keys - A comma-separated list of column names that uniquely identifies a row.

So you have to set Update keys = id if you have just one column id as table row identifier.

About tracking sql queries. Try to add following line into conf\logback.xml

<logger name="org.apache.nifi.processors.standard.PutDatabaseRecord" level="DEBUG"/>

sometimes sql should appear in logs but truly i cant understand the logic in code...

https://github.com/apache/nifi/blob/main/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutDatabaseRecord.java

Upvotes: 1

Related Questions