PostgreSQL-选择日期=“ 01/01/11”的项目 [英] Postgresql - select something where date = "01/01/11"

查看:53
本文介绍了PostgreSQL-选择日期=“ 01/01/11”的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Postgresql中有一个datetime字段,名为 dt。
我想做类似的事情

I have a datetime field in my Postgresql, named "dt". I'd like to do something like

SELECT * FROM myTable WHERE extract (date from dt) = '01/01/11'

这样做的正确语法是什么?

What is the right syntax to do that?

谢谢!

推荐答案

我认为您想投射 dt 日期并修复日期文字的格式

I think you want to cast your dt to a date and fix the format of your date literal:

SELECT *
FROM table
WHERE dt::date = '2011-01-01' -- This should be ISO-8601 format, YYYY-MM-DD

标准版本

SELECT *
FROM table
WHERE CAST(dt AS DATE) = '2011-01-01' -- This should be ISO-8601 format, YYYY-MM-DD

extract 函数不理解日期,它返回一个数字

The extract function doesn't understand "date" and it returns a number.

这篇关于PostgreSQL-选择日期=“ 01/01/11”的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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