Browse Source

fix(nocodb): revise datetime diff year sql for sqlite

pull/4821/head
Wing-Kam Wong 2 years ago
parent
commit
90ed6690ed
  1. 5
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/functionMappings/sqlite.ts

5
packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/functionMappings/sqlite.ts

@ -130,7 +130,10 @@ const sqlite3 = {
sql = `(strftime('%Y', ${datetime_expr1}) - strftime('%Y', ${datetime_expr2})) * 4 + (strftime('%m', ${datetime_expr1}) - strftime('%m', ${datetime_expr2})) / 3`;
break;
case 'years':
sql = `strftime('%Y', ${datetime_expr1}) - strftime('%Y', ${datetime_expr2})`;
sql = `CASE
WHEN (JULIANDAY(${datetime_expr1}) - JULIANDAY(${datetime_expr2})) >= 0 THEN FLOOR(((JULIANDAY(${datetime_expr1}) - JULIANDAY(${datetime_expr2})) / 365.25))
ELSE CEILING(((JULIANDAY(${datetime_expr1}) - JULIANDAY(${datetime_expr2})) / 365.25))
END`;
break;
case 'days':
sql = `JULIANDAY(${datetime_expr1}) - JULIANDAY(${datetime_expr2})`;

Loading…
Cancel
Save