penberg / limbo

Limbo is a work-in-progress, in-process OLTP database management system, compatible with SQLite.
MIT License
993 stars 60 forks source link

feat: add time() scalar function partial support without modifier #158 #252

Closed sonhmai closed 2 months ago

sonhmai commented 2 months ago

Partially support time() scalar function tracked by #158 (not supported modifier yet). ref: https://www.sqlite.org/lang_datefunc.html

Existing date() function support

limbo> explain select date();
addr  opcode             p1    p2    p3    p4             p5  comment
----  -----------------  ----  ----  ----  -------------  --  -------
0     Init               0     4     0                    0   Start at 4
1     Function           1     0     1     date           0   r[1]=func(r[0..])
2     ResultRow          1     1     0                    0   output=r[1]
3     Halt               0     0     0                    0
4     Transaction        0     0     0                    0
5     Goto               0     1     0                    0

added time()

limbo> explain select time();
addr  opcode             p1    p2    p3    p4             p5  comment
----  -----------------  ----  ----  ----  -------------  --  -------
0     Init               0     4     0                    0   Start at 4
1     Function           1     0     1     time           0   r[1]=func(r[0..])
2     ResultRow          1     1     0                    0   output=r[1]
3     Halt               0     0     0                    0
4     Transaction        0     0     0                    0
5     Goto               0     1     0                    0

limbo> select time();
06:14:08
limbo> select time('2023-05-18 23:30:45+07:00');
16:30:45
limbo> select time('invalid');

limbo> select time('now');
06:15:17