oguimbal / pg-mem

An in memory postgres DB instance for your unit tests
MIT License
1.98k stars 97 forks source link

INSERT with interval not support #119

Closed bhargavik12 closed 2 years ago

bhargavik12 commented 3 years ago

An insert query

create table test (col timestamp); insert test (col) values (NOW() + interval '2 years')

data: { error: 'cannot cast type interval to timestamp', code: undefined }, location: { start: 0, end: 0 }

bhargavik12 commented 3 years ago

interval used in queries are not working

oguimbal commented 3 years ago

Wops.

Yes, the implementation of binary operators is pretty simplistic... they assume that both left & right values have the same types, and that the underlying JS primitive supports the "+" operator.

You just found a case where neither of those statements are true.

This issue would require to implement custom operators declaration (like custom functions, but for operators).

Will do. Thanks for the report !

nikhilro commented 3 years ago

Ran into this issue as well with this statement select * from some_tale where created_at > NOW() - INTERVAL '1 DAY' * '4';

abadyan-vonage commented 2 years ago

Ran into this as well when doing the following command: UPDATE rooms SET expiration_date = CURRENT_TIMESTAMP + (10 * '1 minute'::interval) Getting: Error: cannot cast type interval to integer

Any solution to this?

oguimbal commented 2 years ago

Hi,

Too many people had troubles with the lack of support of +/- on interval & date types.

pg-mem is not ready yet to fully support custom operators, but I added to a hack to support this specific use case.

This shipped with with pg-mem@2.1.8. Sorry for the wait, I should have done that much sooner.

abadyan-vonage commented 2 years ago

Awesome! Thanks for the support on this one.