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的更多相关文章

  1. greenplum 数组操作

    参考:http://gpdb.docs.pivotal.io/4390/admin_guide/query/topics/functions-operators.html Table 4. Advan ...

  2. High CPU Usage 原因及分析

    常见的高CPU利用率出现几个原因: Missing Index 统计信息过时 非SARG查询 Implicit Conversions Parameter Sniffing Non-parameter ...

  3. SQL SERVER 内存学习系列(二)-DMV查看内存信息

    内存管理在SQL Server中有一个三级结构.底部是内存节点,这是最低级的分配器,用于SQL Server的内存.第二个层次是由内存Clerk组成,这是用来访问内存节点和缓存存储,缓存存储则用于缓存 ...

  4. 查看SqlServer的内存使用情况

    上一篇提到动态T-SQL会产生较多的执行计划,这些执行计划会占用多少内存呢?今天从徐海蔚的书中找到了答案.动态视图不仅可以查到执行计划的缓存,数据表的页面缓存也可以查到,将SQL整理一下,做个标记. ...

  5. 对SharePoint 2007数据库中一些数据表的使用

    转:http://blog.csdn.net/ma_jiang/article/details/6553392 在工作中接触了一些SharePoint的数据库中的一些表.在此做个总结. 一位高手告诉我 ...

  6. Scala基础入门-代码碎片

    import scala.util.control._ import java.util.Date object Test { def main(args: Array[String]) { // v ...

  7. Optimize For Ad Hoc Workloads

    --临时工作负载优化   即席查询:也就是查询完没放到Cache当中,每次查询都要重新经过编译,并发高的时候很耗性能: 参数化查询: 一方面解决了重编译问题,但随着数据库数据数据的变更,统计信息的更新 ...

  8. SQL 经典应用

    SQL Server日常维护常用的一些脚本整理. 1.sql server开启clr权限: exec sp_configure 'clr enabled', 1 GO RECONFIGURE GO A ...

  9. SQL Server 日常维护经典应用

    SQL Server日常维护常用的一些脚本整理. 1.sql server开启clr权限: GO RECONFIGURE GO ALTER DATABASE HWMESTC SET TRUSTWORT ...

随机推荐

  1. Gym - 101981K The 2018 ICPC Asia Nanjing Regional Contest K.Kangaroo Puzzle 暴力或随机

    题面 题意:给你1个20*20的格子图,有的是障碍有的是怪,你可以每次指定上下左右的方向,然后所有怪都会向那个方向走, 如果2个怪撞上了,就融合在一起,让你给不超过5w步,让所有怪都融合 题解:我们可 ...

  2. 解决VS2008 开发Wince应用程序项目生成速度慢的问题

    最近用VS2008开发Windows Mobile程序,使用C#..NET Compact Framework,发现项目生成速度比较慢.用VS2008打开项目后,开始一段时间生成速度还能忍受,时间一长 ...

  3. Elasticsearch 7.1.1 集群 + 配置身份验证

    一.安装Elasticsearch 1.1 环境说明 Centos7.6 Elasticsearch7.1.1 #挂载数据盘 fdisk /dev/vdb n,p,,回车,回车,wq fdisk -l ...

  4. Winform 异步调用

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  5. Cordova 开发环境搭建及创建第一个app

    整理记录使用cordova创建app应用程序并将其部署至Android系统移动设备上操作过程,具体如下: 一.前期安装环境 1. 安装JDK(java开发工具包) 2. 安装gradle 3. 安装A ...

  6. Unity5.3.6升级到Unity5.4.4 NGUI出现Ignoring menu item NGUI because it is in no submenu!问题解决方案

    目录Assets/Plugins/NGUI/Scripts/Editor/NGUIMenu.cs文件中找到下图(左)所示,改成(右)图所示

  7. elasticsearch模板 template

    https://elasticsearch.cn/article/335 elasticsearch模板 template 可以考虑的学习点: mapping的 _default_类型 动态模板:dy ...

  8. [原创]Linux(CentOS)下安装mongodb

    和上一篇一样,装个这个踩了无数个坑…… 1.下载 wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel55-3.2.12.tgz ...

  9. 学习廖雪峰的Python教程之第一个Python程序

    一.命令行模式和Python交互模式的区分 命令行模式: Python交互模式 二.文本编辑器 1.绝对不能用Word和Windows自带的记事本.Word保存的不是纯文本文件,而记事本会自作聪明地在 ...

  10. 基于神经网络的混合计算(DNC)-Hybrid computing using a NN with dynamic external memory

    前言: DNC可以称为NTM的进一步发展,希望先看看这篇译文,关于NTM的译文:人工机器-NTM-Neutral Turing Machine 基于神经网络的混合计算 Hybrid computing ...