":: date"的应用是什么?在红移? [英] what is the application of "::date" in redshift?
问题描述
我在Amazon redshift的sql代码中看到比较两个日期时使用:: date的地方.我想知道这三行代码之间是否有任何区别:
I see somewhere in the sql code in Amazon redshift that ::date is used when comparing two dates. I am wondering is there any difference between these three lines of code:
start_date < '2016-01-01'
start_date < '2016-01-01'::date
start_date < date('2016-01-01')
推荐答案
在所有三种情况下结果都是相同的.
The result is the same in all three cases.
特别是:
-
start_date < '2016-01-01'
试图将date
与varchar
进行比较,但是Amazon Redshift足够聪明,可以将varchar
转换为日期格式以进行比较.
start_date < '2016-01-01'
is trying to compare adate
with avarchar
, but Amazon Redshift is smart enough to convert thevarchar
into a date format for comparison purposes.
start_date < '2016-01-01'::date
在两个date
字段之间进行了适当的比较.这相当于date '2016-01-01'
.
start_date < '2016-01-01'::date
is doing a proper comparison between two date
fields. This would be equivalent to date '2016-01-01'
.
start_date < date('2016-01-01')
似乎也在比较date
字段,尽管该语法不在
start_date < date('2016-01-01')
appears to also be comparing date
fields, although that syntax isn't in the Date and Time Functions documentation.
使用::date
的一个更有用的示例是比较两个时间戳,而您只希望比较日期,例如:
A more useful example of using ::date
is when comparing two timestamps, and you only wish to compare the date, for example:
select end::date - start::date as days FROM table
这篇关于":: date"的应用是什么?在红移?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!