EvgSkv / logica

Logica is a logic programming language that compiles to SQL. It runs on Google BigQuery, PostgreSQL and SQLite.

Home Page:https://logica.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Number of arguments of `TimestampSub()`

tkawachi opened this issue · comments

Since BigQuery's TIMESTAMP_SUB() has two arguments, I assume that TimestampSub() also has two arguments. However, the following predicate will result in an error.

A(t: TimestampSub(CurrentDate("Asia/Tokyo"), SqlExpr("INTERVAL 9 HOUR",{})));
Compiling:
A(t: TimestampSub(CurrentDate("Asia/Tokyo"), SqlExpr("INTERVAL 9 HOUR",{})))

[ Error ] Built-in function TimestampSub takes (3, 3) arguments, but 2 arguments were given.

Yes, there was a bug with the time arithmetic arity.
Thanks for pointing it out!

I've updated the functions in the codebase and released pypi.

Tested with:

A1(t: DatetimeSub(CurrentDatetime("Asia/Tokyo"), SqlExpr("INTERVAL 9 HOUR",{})));
A1(t: DatetimeAdd(CurrentDatetime("Asia/Tokyo"), SqlExpr("INTERVAL 9 HOUR",{})));
A2(t: DateSub(CurrentDate("Asia/Tokyo"), SqlExpr("INTERVAL 9 day",{})));
A2(t: DateAdd(CurrentDate("Asia/Tokyo"), SqlExpr("INTERVAL 9 day",{})));
A3(t: TimestampSub(CurrentTimestamp(), SqlExpr("INTERVAL 9 day",{})));
A3(t: TimestampAdd(CurrentTimestamp(), SqlExpr("INTERVAL 9 day",{})));
A4(t: TimeSub(CurrentTime("Asia/Tokyo"), SqlExpr("INTERVAL 9 hour",{})));
A4(t: TimeAdd(CurrentTime("Asia/Tokyo"), SqlExpr("INTERVAL 9 hour",{})));

Please let me know if you see further issues.

I have confirmed that it has been fixed.

By the way, is there a better way to write the SqlExpr("INTERVAL 9 hour",{}) part?

Great! Thank you!

If such expression is used a lot, then factoring it out into a function, as follows, helps readability.

IntervalHours(x) = SqlExpr("INTERVAL {x} HOUR", {x:});

A4(t: TimeSub(CurrentTime("Asia/Tokyo"), IntervalHours(9)));
A4(t: TimeAdd(CurrentTime("Asia/Tokyo"), IntervalHours(9)));