postgres时间转换函数
| 函数 | 返回类型 | 描述 | 例子 |
|---|---|---|---|
| to_char(timestamp, text) | text | 把时间戳转换成字串 | to_char(current_timestamp, 'HH12:MI:SS') |
| to_char(interval, text) | text | 把时间间隔转为字串 | to_char(interval '15h 2m 12s', 'HH24:MI:SS') |
| to_char(int, text) | text | 把整数转换成字串 | to_char(125, '999') |
| to_char(double precision, text) | text | 把实数/双精度数转换成字串 | to_char(125.8::real, '999D9') |
| to_char(numeric, text) | text | 把 numeric 转换成字串 | to_char(-125.8, '999D99S') |
| to_date(text, text) | date | 把字串转换成日期 | to_date('05 Dec 2000', 'DD Mon YYYY') |
| to_timestamp(text, text) | timestamp with time zone | 把字串转换成时间戳 | to_timestamp('05 Dec 2000', 'DD Mon YYYY') |
| to_timestamp(double precision) | timestamp with time zone | 把 UNIX 纪元转换成时间戳 | to_timestamp(200120400) |
| to_number(text, text) | numeric | 把字串转换成 numeric | to_number('12,454.8-', '99G999D9S') |
postgresql 相关datetime:
1,date_trunc('month', now())
2,now()-interval '1 month'
1. decode 用 case when a=1 then b else c end
2. 最后一天 to_date(? +'1 mons'::interval,'yyyy-mm') -1
3. 第一天 to_date(?,'yyyy-mm') , date_trunc('month',?)
4.字段别名 加上 as
5.子查询一定要用别名
6.取子树 ,postgresql需人自己写函数,或者用一些有结构特性字段如1.1,1.1.1,1.1.2 来代替
7.trunc(im.createdate) 可改为date_trunc('day',createdate)
date_trunc 与oracle的trunc很像,还可以
SELECT date_trunc('hour', TIMESTAMP '2001-02-16 20:38:40');
Result: 2001-02-16 20:00:00+00
SELECT date_trunc('year', TIMESTAMP '2001-02-16 20:38:40');
Result: 2001-01-01 00:00:00+00
8.postgres-当日, 带时分秒,now() oracle- sysdate
9 postgres-当日,不带时分秒current_date,oracle to_char(sysdate,'YYYY-MM-DD)
10.nvl 全部替换成 coalesce 如 coalesce(im.invoiceamount,0)
11.小数据位数round,例保留一位小数 用select round(2.16,1) Result: 2.2 会四舍五入
12 转志数据类型用::数据类型,如to_number() 改用::numeric
13. 如果取子树,不包含自身,使用函数时,第二个参数取2,如,getorgantree(?,2)
14.项目树函数第一个参数是id,其他的如果地区编码,税务机关分别有参数为编码的,如get..tree(code,level),参数为id的,如get..treebyid(id,level)
15.修改表时,表名不能带别名,如update taxpayer_cognizance_invoice tc 这里taxpayer_cognizance_invoice 不能带别名tc
postgres时间转换函数的更多相关文章
- MySQL 日期、时间转换函数
MySQL 日期.时间转换函数:date_format(date,format), time_format(time,format) 能够把一个日期/时间转换成各种各样的字符串格式.它是 str_to ...
- Mysql日期转换函数、时间转换函数
Mysql日期转换函数.时间转换函数 一.MySQL 获得当前日期时间 函数 1,获得当前日期+时间(date + time)函数:now(): select now(); 结果: :: 2,获得当前 ...
- mysql 时间函数 时间转换函数
时间函数 Now 获取当前时间 current_timestamp 获取当前时间 localtimestamp 时间转换 UNIX_TIMESTAMP "2009-09-15 00:0 ...
- php中时间转换函数
date("Y-m-d H:i",$unixtime) 1.php中获得今天零点的时间戳 要获得零点的unix时间戳,可以使用 $todaytime=strtotime(“tod ...
- JS 时间转换函数 字符串时间转换毫秒(互转)
字符串转化为日期 let util = function(){ Date.prototype.Format = function(fmt) { var o = { "M+" : t ...
- sql时间转换函数--备忘
总是忘记 一.语法: CAST (expression AS data_type) 参数说明: expression:任何有效的SQServer表达式. AS:用于分隔两个参数,在AS之前的是要处理的 ...
- ORACLE函数之日期时间转换函数
1. TO_CHAR 语法:TO_CHAR(X [,format]) 说明:将X按format格式转换成字符串.X是一个日期或者数字.format是一个规定了X採用何种格式转换 ...
- js常用时间转换函数
1.秒转换为时分秒 // 秒转换为时分秒 export function secExchangeMoment(value = 0){ let secondTime = parseInt(value); ...
- SQL Server(第二章) 字符串函数、日期时间函数、转换函数
--1.CONCAT 函数:字符串连接(支持sql server2012 SQL规则 如果与NULL连接返回NILL) SELECT empid,CONCAT(firstname,lastname) ...
随机推荐
- PAT甲级1017. Queueing at Bank
PAT甲级1017. Queueing at Bank 题意: 假设一家银行有K台开放服务.窗前有一条黄线,将等候区分为两部分.所有的客户都必须在黄线后面排队,直到他/她轮到服务,并有一个可用的窗口. ...
- Linux6.9用RPM方式安装MySQL5.7.21
1.下载安装包 wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.21-1.el6.x86_64.rpm-bundle.tar ...
- 2013新mac air直接安装windowns系统无法下一步 键盘鼠标失灵 无法新建分区提示gpt分区解决方案
今天同学拿来了2013款MacbookAir,叫我帮忙装一个Win7系统,保留原来的Mac系统,于是开工.按照教程,准备一个8g的U盘,先进入Air自带的Mac系统(俗称”小牛”),将Win7旗舰版6 ...
- 关闭Spring Boot的Jsckson的FAIL_ON_EMPTY_BEANS
说明:Spring Boot中默认使用了Jackson做JSON的解析. 解决方法: 1.通过注入Bean来实现 错误: org.springframework.http.converter.Http ...
- apache&mod_wsgi&django部署多个项目
今天做好了第二个django项目,但在部署时出了一点小问题,在此记录一下. 1.mod_wsgi 3.4已经支持了部署多个项目,只需在httpd.conf中进行如下配置: WSGIScriptAlia ...
- TJU 2248. Channel Design 最小树形图
最小树形图,測模版.... 2248. Channel Design Time Limit: 1.0 Seconds Memory Limit: 65536K Total Runs: 2199 ...
- 取maven copy部分
mvn deploy:deploy-file -DgroupId=com.mycompany -DartifactId=my-project -Dversion=1.0.0 -Dpackaging=j ...
- 解决Visual Studio 2010 “无法导入以下密钥文件” 错误
错误原文: "错误 1 无法导入以下密钥文件: SamplePlugin.pfx.该密钥文件可能受密码保护.若要更正此问题,请尝试再次导入证书,或手动将证书安装到具有以下密钥容器名称的强名称 ...
- UML建模工具Visio 、Rational Rose、PowerDesign的比较
UML建模工具Visio .Rational Rose.PowerDesign的比较 ROSE是直接从UML发展而诞生的设计工具,它的出现就是为了对UML建模的支持,ROSE一开始没有对数据库端建 ...
- oracle sql 优化大全
转自: http://panshaobinsb.iteye.com/blog/1718233 http://yulimeander.blog.sohu.com/115850824.html 最近遇到了 ...