开发问pg中执行一个简单的语句,多次报错:

> ERROR:  type "sum" does not exist
LINE 1: SELECT SUM
^

  

看看具体的语句,其实是个很简单的语句,怎么会报类型sum不存在呢?

SELECT SUM
(es.money_stock ) 'sum_money',
es.material_no,
es.price
FROM
es
GROUP BY
es.material_no,
es.price;

  

其实这是的问题在于select语句中列的别名的写法规范问题。以下是pg文档中的描述:

在SQL标准中,只要新列名是有效的列名(即与任何保留关键字不同),就可以在输出列名之前省略可选关键字AS。
PostgreSQL的限制更严格:如果新的列名完全匹配任何关键字,则保留AS,无论是否是保留字。
推荐的做法是使用AS或双引号输出列名,以防止与将来添加关键字的任何可能的冲突。

在FROM项中,标准sql和PostgreSQL都允许省略AS之前的AS,如果该别名不是保留的关键字。但是由于语法上的歧义,这对于输出列名称是不切实际的。

所以这里真正的问题是单引号的使用。去掉单引号即可。 当然也可以将单引号换成双引号。

ERROR: type "sum" does not exist的更多相关文章

  1. react-native run-android Starting: Intent Error type 3 Error: Activity class does not exist

    使用”react-native run-android”命令运行android应用时,如果常常出现如下错误: Starting the app (/home/xxx/soft/sdk//platfor ...

  2. [转载]Vertica “ERROR: Too many ROS containers exist”

    最近在用Vertica的时候碰到一个问题,Vertica在运行了一段时间后总是出现类似下面的错误 1: java.sql.SQLException: [Vertica][VJDBC](5065) 2: ...

  3. windows 8 安装 oracle 11g 报错:command line option syntax error,type command/? for help

    windows 8 安装 oracle 11g 报错:command line option syntax error,type command/? for help 在windows8操作系统上安装 ...

  4. PostgreSql问题:ERROR: column "1" does not exist

    摘录自:http://blog.csdn.net/shuaiwang/article/details/1807421 在PostgreSQL中,不论是在pgAdmin中还是在命令行控制台里面,在SQL ...

  5. ssh 报error: kex protocol error: type 30 seq 1

    由于近期服务器升级了openssl,在使用navicat连接数据库报 查看日志 sshd[1990]: error: kex protocol error: type 30 seq 1 [preaut ...

  6. pgsql 执行建库脚本时候出现ERROR: relation "xxx_id_seq" does not exist

    1. 问题: ERROR: relation "xxx_id_seq" does not exist 2. 出现原因:由于表中建立了自增字段,id定义为Serial 类型,当执行完 ...

  7. [PAClient Error] Error: E4356 File does not exist armv7

    [PAClient Error] Error: E4356 File does not exist: /Users/tt/PAServer/scratch-dir/Administrator-snIO ...

  8. Spring Cloud / Spring Boot There was an unexpected error (type=Unauthorized, status=401). Full authentication is required to access this resource.

    访问EndPoint时会出现没有权限   There was an unexpected error (type=Unauthorized, status=401). Full authenticat ...

  9. 安装SQL Servre2000时提示“command line option syntax error! type command /? for help”

    问题: 当程序正在安装ms数据访问组件时,弹出错误提示框:command line option syntax error,type command/? for help,点击确定继续:到了程序正在安 ...

随机推荐

  1. Thinkphp5.1允许uni-app的H5跨域请求接口解决方法

    情景: uni-app使用vue框架开发混合APP,虽然APP或者小程序没有跨域,但希望就是写完这个既有H5,又有APP,小程序等,所以能通过后端解决跨域最好.但是不知道是vue的原因还是什么,在PH ...

  2. css 带换行的垂直居中

    span{ display:flex; justify-content:left; align-items:center; height:100%; width:100%; }

  3. Sublime Text3 安装 CTags 插件出现乱码

    1.下载ctags.exe 可以直接下载我上传好的资源:http://download.csdn.net/download/zhaoxd200808501/9971251.或者网络上其他地方也可以下载 ...

  4. golang之数据转换

    golang按位取反符号和异或符号都是^. fmt.Printf("0x%X\n", 0xFF^0x55) var a uint8 = 0x55 fmt.Printf(" ...

  5. .NET Core中Quartz.NET的依赖注入

    目录 介绍 项目概况 创建配置文件 使用构造函数注入 使用选项模式 结论 介绍 Quartz.NET是一个方便的库,允许您通过实现IJob接口来安排重复任务.然而,它的局限性在于,默认情况下,它仅支持 ...

  6. Git 冲突:Your local changes would be overwritten by merge. Commit, stash or revert them to proceed.

    解决方案有三种: 1,无视,直接commit自己的代码. git commit -m "your msg" 2,stash stash翻译为“隐藏”,如下操作: git stash ...

  7. xargs的用法

    处理带有空格的文件名 #我们创建了3个日志文件, 且故意让文件名称中都含有空格 [roc@roclinux ~]$ ;i<;i++)); do touch "test ${i}.log ...

  8. iframe跨域修改子页面内容或样式

    哈哈 当然不能啦 要是能修改百度logo早就是我的头像了

  9. Codeforces Round #558 (Div. 2)-Cat Party (Hard Edition)-(前缀和 + 模拟)

    http://codeforces.com/problemset/problem/1163/B2 题意:有n天,每天有一个颜色,截取前x天,随便抽掉一天,使剩下的各个颜色出现的次数相等. 解题,也可以 ...

  10. 什么是cdn?

    CDN加速意思就是在用户和我们的服务器之间加一个缓存机制, 通过这个缓存机制动态获取IP地址根据地理位置,让用户到最近的服务器访问. 那么CDN是个啥? 全称Content Delivery Netw ...