psql的时间类型,通过时间查询
psql的时间类型,通过时间查询
psql有date/timestamp类型,date只显示年月日1999-01-08,而timestamp显示年月日时分秒 1999-01-08 09:54:03.249
在我们写sql语句,根据时间进行查询的时候
有下面一张表demo,
Column | Type | Collation | Nullable | Default |
id | integer | not null | nextval('build_log_id_seq'::regclass) | |
content | character varying(50) | not null | NULL::character varying | |
createDate | timestamp without time zone | not null | NULL::character varying | |
write_date | date | not null | NULL::character varying |
表内数据:
id | content | createDate | write_date |
1 | 内容1 | 2018-04-26 09:54:03.221 | 2018-01-02 |
2 | 内容2 | 2018-02-13 08:15:12.222 | 2018-01-03 |
3 | 内容3 | 2018-06-18 19:15:12.222 | 2018-01-04 |
4 | 内容4 | 2018-08-12 12:15:12.22 | 2018-01-05 |
表中的write_date是date类型可以直接使用=,select * from table where time='2018-01-02'
表中的createDate是timestamp类型,如果使用=号,但是我们不能精确到十分秒,所以用=号就不会查出内容,
我们可以使用><或者使用between and语句
例如:
查询4月26日创建的数据:
select * from demo where createDate >= '2018-04-26' and createDate < '2018-04-27'
或者:
select * from demo where createDate between '2018-04-26' and '2018-04-27'
还有一种,我们将字符串转成时间类型,
select * from demo where createDate >= '2018-04-26'::date and createDate < ( '2018-04-26'::date + '1 day'::interval )
psql的时间类型,通过时间查询的更多相关文章
- Access数据库中日期时间类型的时间段查询
例: select ID,预设点,备注 from 预设点派车预警 where ( 到达时间>=#2013-01-01 12:12:12# and 到达时间<=#2016-01-24 2 ...
- MySQL日期数据类型、时间类型使用总结
MySQL日期数据类型.时间类型使用总结 MySQL日期数据类型.MySQL时间类型使用总结,需要的朋友可以参考下. MySQL 日期类型:日期格式.所占存储空间.日期范围 比较. 日期类型 ...
- MySQL日期数据类型、MySQL时间类型使用总结
MySQL:MySQL日期数据类型.MySQL时间类型使用总结 MySQL 日期类型:日期格式.所占存储空间.日期范围 比较. 日期类型 存储空间 日期格式 日期范围 ------------ --- ...
- mysql日期时间类型总结
MySQL 日期类型:日期格式.所占存储空间.日期范围 比较. 日期类型 存储空间 日期格式 日期范围 ------------ ---- ...
- MySQL 时间类型字段的分析
日期类型 存储空间 日期格式 日期范围---------- ...
- MySQL日期数据类型和时间类型使用总结
转自: http://blog.chinaunix.net/space.php?uid=11327712&do=blog&id=32416 MySQL 日期类型:日期格式.所占存储空间 ...
- MySQL:MySQL日期数据类型、MySQL时间类型使用总结
MySQL 日期类型:日期格式.所占存储空间.日期范围 比较. 日期类型 存储空间 日期格式 日期范围------------ -------- ...
- 【spring mvc】后台API查询接口,get请求,后台Date字段接收前台String类型的时间,报错default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'createDate';
后台API查询接口,get请求,后台Date字段接收前台String类型的时间筛选条件 后台接口接收 使用的实体 而createDate字段在后台实体中是Date类型 报错信息: org.spring ...
- MySQL时间类型datetime、bigint及timestamp的查询效率
前期数据准备 通过程序往数据库插入 50w 数据 数据表: CREATE TABLE `users` ( `id` int(11) NOT NULL AUTO_INCREMENT, `time_dat ...
随机推荐
- VMware 三种网络配置解释
https://blog.csdn.net/noob_f/article/details/51099040 ifconfig -a 网卡名称
- 解决一个通过 WebReference 调用 WCF 时自定义 DataContract 类参数提交的问题
先看一下VS2013自动创建默认的IService1.vb,注意自定义的数据契约 CompositeType ' 注意: 使用上下文菜单上的“重命名”命令可以同时更改代码和配置文件中的接口名“ISer ...
- 奇点云COO刘莹应邀出席《APEC SME大数据与人工智能论坛》
10月24日-25日,由亚太经合组织(APEC).韩国中小型及初创企业管理局(the Ministry of SMEs & Startups of Korea)主办的「APEC SME 大数据 ...
- highcharts 设置柱子之间的距离 柱子宽度
plotOption : { column : { // 设置每个柱自身的宽度 pointWidth : // x轴每个点只用一个柱,则这个属性设置的是相邻的两个点的柱之间的间距. // 如果x轴每个 ...
- yet|women teachers|waters|
Though the sore be healed, a scar may remain on her face, which makes her sad sometimes. 题目解析 考查连词的 ...
- TB3_Autorace之交通杆检测
利用blob检测算法识别交通杆,控制TB3机器人完成对交通杆的起停动作! 上一篇博文中<TB3_Autorace之路标检测>订阅了原始图像信息,经过SIFT检测识别出道路交通标志,这里我们 ...
- MAYA卸载/完美解决安装失败/如何彻底卸载清除干净MAYA各种残留注册表和文件的方法
在卸载MAYA重装MAYA时发现安装失败,提示是已安装或安装失败.这是因为上一次卸载后没有清理干净,系统会误认为已经安装过了.有的同学是新装的系统也会出现安装失败的情况,这是因为C++ 或者.NET的 ...
- tftpd64-SE使用
使用场景: 把windows下的文件写入到linux(嵌入式设备中): 下载地址: https://bitbucket.org/phjounin/tftpd64/wiki/Download%20Tft ...
- 吴裕雄--天生自然 R语言开发学习:导入数据
2.3.6 导入 SPSS 数据 IBM SPSS数据集可以通过foreign包中的函数read.spss()导入到R中,也可以使用Hmisc 包中的spss.get()函数.函数spss.get() ...
- npm install依赖时,常见错误
1.npm install依赖时,报错:npm ERR! Unexpected end of JSON input while parsing near '...gin":"^1. ...