":: date"的应用是什么?在红移? [英] what is the application of "::date" in redshift?

查看:91
本文介绍了":: date"的应用是什么?在红移?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在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'试图将datevarchar进行比较,但是Amazon Redshift足够聪明,可以将varchar转换为日期格式以进行比较.

  • start_date < '2016-01-01' is trying to compare a date with a varchar, but Amazon Redshift is smart enough to convert the varchar 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆