Support Questions

Find answers, ask questions, and share your expertise

PutSql With Date as argument

avatar

Hi ,

I'm trying some examples with PutSQL processor. While doing trying the examples, gone through the PutSql.java code. When i checked the PutSql.java file , found that Date and Time data types always expects only Long.

Why is this restriction? Is it possible to make it to accept String also?

1 ACCEPTED SOLUTION

avatar
Master Guru

It seems feasible to remove this restriction from Date and Time data types, as was done for Timestamps in NIFI-3430. Please feel free to write up a Jira case for this improvement.

In the meantime, if you are trying to do something like use the value '2017-02-21' in a field specified as Date/Time type, you could first change the value (possibly in an UpdateAttribute processor) using NiFi Expression Language's toDate() function. So if you have an attribute such as 'my.date.string' set to '2017-02-21' you could set an attribute 'my.date' equal to the following:

${my.date.string:format('yyyy-MM-dd')}

View solution in original post

3 REPLIES 3

avatar
Master Guru

It seems feasible to remove this restriction from Date and Time data types, as was done for Timestamps in NIFI-3430. Please feel free to write up a Jira case for this improvement.

In the meantime, if you are trying to do something like use the value '2017-02-21' in a field specified as Date/Time type, you could first change the value (possibly in an UpdateAttribute processor) using NiFi Expression Language's toDate() function. So if you have an attribute such as 'my.date.string' set to '2017-02-21' you could set an attribute 'my.date' equal to the following:

${my.date.string:format('yyyy-MM-dd')}

avatar
Contributor

Hi

I tried putting attribute " ${my.date.string:format('yyyy-MM-dd')} " in update attribute got some error in PUTSQL, its not updating the value into database.

please find the image of my dataflow in the attachment

Thanks

nifidatepng.png

avatar

Hi Matt,

Thanks for suggestion and it worked 🙂 Tried like this:- ${my.date:toDate("yyyy-MM-dd"):toNumber()}

Thanks alot.

--Srikanth.