node-oracledb icon indicating copy to clipboard operation
node-oracledb copied to clipboard

Can't compare a Date object to a Date column in a Select

Open lstroud opened this issue 11 years ago • 3 comments

I have a query that selects some data from a table, including a column that is a DATE datatype. When I then select from another table, using that value as a bind parameter, I get no results (and should - joining this same data in a query works).

//some pseudo code results = connection.execute("select mydate from mytable where somecondition = 'blah'", [], {outFormat: oracle.OBJECT}, function(err, results){ results.rows.forEach(function(row){ connection.execute("select name, location from myothertable where thedate = :dateparam", {dateparam: row.rundate}, {outFormat: oracle.OBJECT}, function(detailerr, detailresults) { console.dir(detail_results); }); }); });

My understanding is that DATE column values are converted to OCIDateTime. Does that conversion effect the ability to compare the result to a DATE column?

I tried switch to to_char for the comparison, but the conversion to the local timezone breaks it (dates are not stored with timezone information)

Is there a way to use the javascript Date the the driver returns to bind against a DATE column in a select statement?

lstroud avatar Apr 07 '15 20:04 lstroud

I found a work around (about as soon as I posted this) :).

If i trunc the comparison it will work. So this: select name, location from myothertable where thedate = :dateparam becomes select name, location from myothertable where thedate = trunc(:dateparam)

Still seems that I should not have to do that.

lstroud avatar Apr 07 '15 20:04 lstroud

I'm going to mark this as a bug, but really it needs more detailed analysis which will happen when we review date handling. It is common to need to truncate dates in Oracle queries to be able to do exact matches.

cjbj avatar Apr 14 '15 18:04 cjbj

@lstroud this was an interesting problem. We have fixed it in node-oracledb 1.0. Try again.

cjbj avatar Aug 17 '15 07:08 cjbj