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) ...
随机推荐
- 【20181024T2】小C的序列【GCD性质+链表】
题面 [错解] 一眼不可做啊 哎分治? 算不了啊 真的是,打暴力走人 20pts (事实上,还有20pts是随机数据,加个小小的特判就可以) [正解] 首先,从l开始往后gcd最多只有O(log)种取 ...
- 20162327WJH《程序设计与数据结构》课程总结
20162327<程序设计与数据结构>课程总结 一.每周作业链接汇总 预备作业1:第一篇博客主要谈论了对本学期学习的展望,树立了一个目标. 预备作业2:简单的谈了谈自己的优势和一些成功的案 ...
- python3-开发进阶Flask的基础
一.概述 最大的特点:短小精悍.可拓展强的一个Web框架.注意点:上下文管理机制,依赖wsgi:werkzurg 模块 二.前奏学习werkzurg 先来回顾一个知识点:一个类加括号会执行__init ...
- [转]android系统各种音量的获取与设置
获取系统音量 通过程序获取android系统手机的铃声和音量.同样,设置铃声和音量的方法也很简单! 设置音量的方法也很简单,AudioManager提供了方法:publicvoidsetStreamV ...
- Delphi CompilerVersion Constant / Compiler Conditional Defines
http://delphi.wikia.com/wiki/CompilerVersion_Constant The CompilerVersion constant identifies the in ...
- Codeforces Round #FF (Div. 1) B. DZY Loves Modification
枚举行取了多少次,如行取了i次,列就取了k-i次,假设行列单独贪心考虑然后相加,那么有i*(k-i)个交点是多出来的:dpr[i]+dpc[k-i]-i*(k-i)*p 枚举i取最大值.... B. ...
- Hbulider 支持less保存自动编译
设置less配置:文件写 .less,路径找lessc.cmd,找不到就下载,命令参数写:%FileName% %FileBaseName%.css这样以后就可以less文件自动生成css了!
- TortoiseSVN解决冲突
解决冲突Resolving Conflicts有时候,你从仓库更新文件时会发生一些冲突.当两个或更多开发人员对同一个文件的某几行做 了修改,就会产生冲突.因为Subversion对你的项目一无所知,他 ...
- redis cluster 设置密码做集群时gem下client.rb文件修改
redis节点有设置密码,然后在创建集群的时候没有设置密码的命令 ./redis-trib.rb create --replicas 1 127.0.0.1:6381 127.0.0.1:6382 1 ...
- react的传值类型PropTypes简单说明
1.首先可以有那么多种类型 propTypes: { // 可以声明 prop 为指定的 JS 基本类型.默认 // 情况下,这些 prop 都是可传可不传的. optionalArray: Reac ...