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) ...
随机推荐
- 【DLX算法】poj2676 Sudoku
DLX算法求解精确覆盖问题模板.赛场上可以参见白书. #include<cstdio> #include<cstring> #include<vector> usi ...
- spring核心及常用技术
一.核心内容 1.依赖注入(控制反转) 1)什么是依赖注入 spring将实例的创建交给spring容器(BeanFactory或ApplicationContext)管理,当实例创建后通过设值或构造 ...
- SCOJ 4429: frog's dice 最大流
4429: frog's dice 题目连接: http://acm.scu.edu.cn/soj/problem.action?id=4429 Description frog has many d ...
- 利用BusyBox ~私人定制 My LINUX~
前言 我在今天在这里跟大家详细地探讨一下Linux系统的定制过程和实现例如.用户能够远程登录:和Nginx能够稳定地运行在我们私人定制的LINUX系统上.一步一步从头开始定制属于我们自己的系统. 正文 ...
- 安装VS组件提示“所选驱动不再有效。继续安装之前,请先检查安装路径的设置。”要怎么办?
电脑里面原来装了VS2010,包括的组件有VB和C++,现在想添加C#,结果安装的时候就提示“所选驱动不再有效.继续安装之前,请先检查安装路径的设置”,安装路径在C盘,还有40个G,不知道该怎么办? ...
- 更为详细的介绍Hadoop combiners-More about Hadoop combiners
Hadoop combiners are a very powerful tool to speed up our computations. We already saw what a combin ...
- JOIN与EXISTS(子查询)的效率研究
使用MySQL提供的Sample数据库Sakila 现将profiling打开,用来一会查看sql执行时间 set profiling=1; exists 子查询与 join联接效率的对比,功能:查看 ...
- PowerDesigner教程系列(二)概念数据模型
目标:本文主要介绍PowerDesigner概念数据模型以及实体.属性创建.一.新建概念数据模型1)选择File-->New,弹出如图所示对话框,选择CDM模型(即概念数据模型)建立模型. 2) ...
- django cookie and session
cookie和session 1.cookie不属于http协议范围,由于http协议无法保持状态,但实际情况,我们却又需要“保持状态”,因此cookie就是在这样一个场景下诞生. cookie的工作 ...
- IOS UITableView删除功能
UITbableView作为列表展示信息,除了展示的功能,有时还会用到删除,比如购物车等.删除功能可以直接使用系统自带的删除功能,当横向轻扫cell时,右侧出现红色的删除按钮,点击删除当前cell. ...