A function with two datetime parameters receives the string '00:00:00.000000' for the second argument
See original GitHub issueDescribe the bug
Register a function with two parameters, both of type DataType.time. The second argument passed to the function implementation is never the argument passed in the SQL, it is always the string ‘00:00:00.000000’.
To Reproduce
This test fails (I poked it into function-calls.spec.ts):
it('passes multiple arguments', () => {
db.public.registerFunction({
name: 'datediff',
args: [DataType.time, DataType.time],
returns: DataType.integer,
implementation: (arg1, arg2) => {
assert.instanceOf(arg1, Date);
assert.instanceOf(arg2, Date);
return Math.trunc(arg1 / 86400) - Math.trunc(arg2 / 86400);
},
});
expect(many(`select datediff(date '2008-03-13', date '2008-02-12')`))
.to.equal(29);
});
with the assertion failure:
1) Functions
passes multiple arguments:
AssertionError: expected '00:00:00.000000' to be an instance of Date
pg-mem version
2.4.3 (and tip of master branch)
Issue Analytics
- State:
- Created a year ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
python - How to convert a string into a parameter of a function?
You have to convert the dictionary so that the period is pointing to the quantity. Then use dictionary unpacking normally. import datetime ......
Read more >Date() constructor - JavaScript - MDN Web Docs - Mozilla
The Date() constructor can create a Date instance or return a string representing the current time.
Read more >how to check if two dates are equal using gs.dateDiff function
Calculates the difference between two dates. This method expects the earlier date as the first parameter and the later date as the second...
Read more >MySQL 8.0 Reference Manual :: 12.7 Date and Time Functions
DATETIME if the first argument is a DATETIME (or TIMESTAMP ) value, or if the first argument is a DATE and the unit...
Read more >DateTime Functions Cheat Sheet - Alteryx Community
This function is used to convert a datetime field into a string. (See Alteryx Help for more information on data types.) The two...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Right, this was PEBKAC — see, I’m implementing a different SQL dialect, translating into PostgreSQL to use pg-mem underneath, and the other dialect calls the time-of-day type
timeofdayand the date-time typetime, and I totally tripped on my shoelaces juggling these differences in my head 😁 … thanks!The issue with cast should be fixed in
pg-mem@2.5.0