开发者

sqlite3 date and interval functions

开发者 https://www.devze.com 2023-01-03 13:05 出处:网络
I wonder whether sqlite3 supports interval function. The following statement is accepted by PostgreSQL, however sqlite3 failed to parse it;

I wonder whether sqlite3 supports interval function. The following statement is accepted by PostgreSQL, however sqlite3 failed to parse it;

select
 ...
from 
 orders
where
 ...
 and o_orderdate < date '1995-03-01' + interval '3' month 

Error: near line 4: near "'1995-03-01'": syntax error

Then, I modified the statement a little bit such as;

and o_orderdate < date('1995-03-01') + interval '3' month

This time the error was; Error: near line 4: near "'3'": syntax error

Unfortunately, same trick did not work 开发者_开发问答for the interval function i.e.

and o_orderdate < date('1995-03-01') + interval('3' month)

or

and o_orderdate < date('1995-03-01') + interval('3') month

or even

and o_orderdate < date('1995-03-01') + interval(3 month)

still gave me the syntax error.

Maybe sqlite3 does not support interval function or am I missing something in its usage?

Thanks a lot


and o_orderdate < date('1995-03-01', '+3 month')

reference of date and time functions in SQLite


try this:

and date(o_orderdate) < date('1995-03-01','+3 month')

In order to calculate dates, you must inform to SQLite that your database field is a date: date(o_orderdate)

SQLite syntax is pretty unflexible, so it's important to make sure that the + sign has no spaces to the following number: '+3 month'

0

精彩评论

暂无评论...
验证码 换一张
取 消