PostgreSQL sum typecasting as a bigint
https://stackoverflow.com/questions/20203081/postgresql-sum-typecasting-as-a-bigint
Question:
I am doing the sum() of an integer column and I want to typecast the result to be a bigint - to avoid an error. However when I try to use sum(myvalue)::bigint it still gives me an out of range error.
Is there anything that I can do to the query to get this to work? Or do I have to change the column type to a bigint?
------------------
Answer:
Try sum(myvalue::bigint)
The result is obviously bigger than what bigint
could hold:
-9223372036854775808 to +9223372036854775807
Postgres returns numeric
in such a case. You shouldn't have to do anything, it should just work without explicit cast.
If it doesn't, you can cast the base type to bigint
, thereby forcing the result to be numeric
in any case.
SELECT sum(myvalue::int8) ...
PostgreSQL sum typecasting as a bigint的更多相关文章
- greenplum 数组操作
参考:http://gpdb.docs.pivotal.io/4390/admin_guide/query/topics/functions-operators.html Table 4. Advan ...
- High CPU Usage 原因及分析
常见的高CPU利用率出现几个原因: Missing Index 统计信息过时 非SARG查询 Implicit Conversions Parameter Sniffing Non-parameter ...
- SQL SERVER 内存学习系列(二)-DMV查看内存信息
内存管理在SQL Server中有一个三级结构.底部是内存节点,这是最低级的分配器,用于SQL Server的内存.第二个层次是由内存Clerk组成,这是用来访问内存节点和缓存存储,缓存存储则用于缓存 ...
- 查看SqlServer的内存使用情况
上一篇提到动态T-SQL会产生较多的执行计划,这些执行计划会占用多少内存呢?今天从徐海蔚的书中找到了答案.动态视图不仅可以查到执行计划的缓存,数据表的页面缓存也可以查到,将SQL整理一下,做个标记. ...
- 对SharePoint 2007数据库中一些数据表的使用
转:http://blog.csdn.net/ma_jiang/article/details/6553392 在工作中接触了一些SharePoint的数据库中的一些表.在此做个总结. 一位高手告诉我 ...
- Scala基础入门-代码碎片
import scala.util.control._ import java.util.Date object Test { def main(args: Array[String]) { // v ...
- Optimize For Ad Hoc Workloads
--临时工作负载优化 即席查询:也就是查询完没放到Cache当中,每次查询都要重新经过编译,并发高的时候很耗性能: 参数化查询: 一方面解决了重编译问题,但随着数据库数据数据的变更,统计信息的更新 ...
- SQL 经典应用
SQL Server日常维护常用的一些脚本整理. 1.sql server开启clr权限: exec sp_configure 'clr enabled', 1 GO RECONFIGURE GO A ...
- SQL Server 日常维护经典应用
SQL Server日常维护常用的一些脚本整理. 1.sql server开启clr权限: GO RECONFIGURE GO ALTER DATABASE HWMESTC SET TRUSTWORT ...
随机推荐
- Coursera Algorithms week1 算法分析 练习测验: 3Sum in quadratic time
题目要求: Design an algorithm for the 3-SUM problem that takes time proportional to n2 in the worst case ...
- kafka参数在线修改
当kafka集群单个节点出现磁盘满了,需要清理历史topic数据:方法如下 1): 停掉kafka进程,将kafka的server.properties中的log.retention.hours=1/ ...
- hdu5673-Robot
题目: http://acm.hdu.edu.cn/showproblem.php?pid=5673 好久没打BC,当时这场过了3题,hack了一个,马马虎虎吧,因为前三个题确实不难. 这个是那场的第 ...
- Gym - 101981M The 2018 ICPC Asia Nanjing Regional Contest M.Mediocre String Problem Manacher+扩增KMP
题面 题意:给你2个串(长度1e6),在第一个串里找“s1s2s3”,第二个串里找“s4”,拼接后,是一个回文串,求方案数 题解:知道s1和s4回文,s2和s3回文,所以我们枚举s1的右端点,s1的长 ...
- 另一种压缩图片的方法---Machine learning 之 PCA(Principle Component Analysis)
PCA最主要的用途是用来减少特征向量的数目,N个特征向量 减小到 K个特征向量.如果为了可视化,k可以使3 或者 2.这样可以加速算法的学习速度. PCA用来压缩图像同一有效. 具体方式以及原理在gi ...
- 构造函数中this,return的详解
function Foo(name,age){ this.name=name; this.age=age; } var foo=new Foo("Tom",14); foo.nam ...
- 搭建Hive所遇到的坑
##一.基本功能: 1.启动hive时报错 java.lang.ExceptionInInitializerError at java.lang.Class.forName0(Native Metho ...
- 【Linux】tmpfs简介及增加方式
一. 什么是tmpfs? tmpfs是一种基于内存的文件系统,它和虚拟磁盘ramdisk比较类似,但不完全相同,和ramdisk一样,tmpfs可以使用RAM,但它也可以使用swap分区来存储.而且传 ...
- 面试回答问题要防范hr的陷阱
面试技巧是大众化的,比较实在.在经历的各种面试中,最不容易防范的面试就是“拉呱”(山东方言,聊天的意思),这样子自己容易放松警惕. 看看下面的,就知道应该怎么应对这些“滑头”的HR! 1.我们为什么要 ...
- 【sqli-labs】 less28a GET- Blind based -All you Union&Select Belong to us -String -Single quote-parenthesis(GET型基于盲注的去除了Union和Select的单引号带括号字符型注入)
和less28没什么区别,直接上个payload吧 http://192.168.136.128/sqli-labs-master/Less-28a/?id=0')%a0uNion%a0sElect% ...