ERROR: Functions in index expression must be marked IMMUTABLE
在创建函数索引时遇到报错,报错信息即为标题,下面是详细信息。
1 表定义
1 |
skytf=> \d test_39; |
现在需要在字段 “skyid”, “create_time” 上创建联合索引。
2 创建索引
1 |
skytf=> create index CONCURRENTLY idx_test_skyid_ctime on test_39 using btree (skyid, to_char(create_time, 'YYYY-MM-DD') ); |
创建函数索引报错,”functions in index expression must be marked IMMUTABLE” ,意思为建立函数索引时 函数必须标识为 “IMMUTABLE”。
3 查看 to_char 函数
1 |
skytf=> \df to_char(); |
4 以 postgres 超级用户连接,修改 to_char 函数属性
1 |
skytf=# alter function to_char(timestamp with time zone, text) IMMUTABLE; |
备注:由于表 test_39 上的列 create_time 类型为 “timestamp with time zone” , 所以修改函数时应该修改函数 to_char(timestamp with time zone, text),为了安全己见,不要直接修改 to_char 函数,建议新建一个 IMMUTABLE 属性的 to_char_immutable 函数。
5 验证是否生效
1 |
skytf=> \ef to_char(timestamp with time zone, text) |
从“IMMUTABLE STRICT” 中可以看出,函数已经修改成 “IMMUTABLE”属性。
6 以 skytf 连接, 再次创建索引
1 |
skytf=> create index CONCURRENTLY idx_test_skyid_ctime on test_39 using btree (skyid, to_char(create_time, 'YYYY-MM-DD') ); |
备注:在修改函数 to_char(timestamp with time zone, text) 属性后,创建索引就成功了。
1 |
skytf=> \d test_39 |
7 手册上关于 “IMMUTABLE” 属性解释
IMMUTABLE indicates that the function cannot modify the database and always returns the same result when given the same argument values; that is, it does not do database lookups or otherwise use information not directly present in its argument list. If this option is given, any call of the function with all-constant arguments can be immediately replaced with the function value.
8 总结
函数的默认属性为 “VOLATILE”, 即可变的,在创建函数索引时,需要将引用函数的属性改为”IMMUTABLE”, 即稳定的,函数索引才能创建成功。也就是说,只有属性为稳定的函数,才能用来创建函数索引。
ERROR: Functions in index expression must be marked IMMUTABLE的更多相关文章
- Error: Error setting TTL index on collection : sessions
Error: Error setting TTL index on collection : sessions 一.步骤一: 这个问题一般是直接升级 mongodb和connect-mongo的版本为 ...
- Solve Error Debug Assertion Failed Expression vector iterators incompatible Using PCL in Release Mode of VS2010
When using PCL 1.4.0 in the release mode building under VS2010, we might sometime get the error &quo ...
- 解决报错error the @annotation pointcut expression is only supported at Java 5
eclipse搭建环境后报错 error the @annotation pointcut expression is only supported at Java 5 错误意思大致是:注释切入点表达 ...
- 编译时错误之 error C2338: tuple_element index out of bounds
part 1 编译器 vs2015 VC++. 完整的错误信息粘贴如下: d:\program files (x86)\microsoft visual studio 14.0\vc\include\ ...
- Type Syntax error, insert ")" to complete Expression
今天倒持了 几个小时! 愣是 没有明确 ,为什么我的JSP的第一行没有代码? 还是报错! 错误是: Description Resource Path Location Type Sy ...
- bullet, iOS真机编译错误error: identifier or immediate expression expected解决方法
刚才发现c3dEngine2(http://git.oschina.net/wantnon2/c3dEngine2 或 https://github.com/wantnon2/c3dEngine2)的 ...
- ERROR 1709 (HY000): Index column size too large. The maximum column size is 767 bytes.
MySQL版本5.6.35 在一个长度为512字符的字段上创建unique key报错 CREATE DATABASE dpcs_metadata DEFAULT CHARACTER SET utf8 ...
- C++ error:Debug Assertion Failed.Expression:_BLOCK_TYPE_IS_VALID(phead->nBlock)
Debug Assertion Failed.Expression:_BLOCK_TYPE_IS_VALID(phead->nBlockUse) 关于上面这个错误,我在上一篇文章中的程序遇到过了 ...
- error the @annotation pointcut expression is only supported at Java 5 compliance
今天碰到这个错误,在网上找了下,是因为aspectjweaver.jar用的是1.5.3 本地eclipse的jdk版本为1.7 下载高版本的aspectjweaver.jar会解决此问题 http: ...
- digestmd5.c:4037:15: error: #elif with no expression
执行如下:sed -i.bak 's/#elif WITH_DES/#elif defined(WITH_DES)/' \ plugins/digestmd5.c
随机推荐
- 【每日一题】【回溯】2021年12月29日-93. 复原 IP 地址
有效 IP 地址 正好由四个整数(每个整数位于 0 到 255 之间组成,且不能含有前导 0),整数之间用 '.' 分隔. 例如:"0.1.2.201" 和 "192.1 ...
- SpringBoot内置tomcat启动过程及原理
作者:李岩科 1 背景 SpringBoot 是一个框架,一种全新的编程规范,他的产生简化了框架的使用,同时也提供了很多便捷的功能,比如内置 tomcat 就是其中一项,他让我们省去了搭建 tomca ...
- 使用WPF或AspNetCore创建简易版ChatGPT客户端,让ChatGPT成为你的私人助理
前言:前一天写的一个ChatGPT服务端,貌似大家用起来还不是那么方便,所以我顺便用WPF和AspNetCore的webapi程序做个客户端吧,通过客户端来快速访问chatgpt模型生成对话. 1 ...
- 推荐8个提高工作效率的IntelliJ插件
前言 欢迎关注微信公众号「JAVA旭阳」交流和学习 IntelliJ目前已经成为市面上最受欢迎的Java开发工具,这得益于里面非常丰富的插件机制.本文我将分享在日常开发中我经常使用的5个插件,它们可以 ...
- 彻底弄懂Javascript模块导入导出
笔者开始学习Javascript的时候,对模块不太懂,不知道怎么导入模块,导出模块,就胡乱一通试 比如 import xx from 'test.js' 不起作用,就加个括号 import {xx} ...
- 线性方程组的直接解法——Gauss消去法
考虑线性方程组 \[\mathrm{A}x=\mathrm{b} \] 其中,\(\mathrm{A}=(a_{ij})_{n\times n}\),\(\mathrm{b}=[b_1,b_2,\cd ...
- 用Dockerfile制作一个java应用镜像,ubuntu基础篇
内容介绍: (1) 本章目的,将一个自行开发的java程序webpay-api,制作为docker自定义镜像,并且进行部署. (2) 实验环境: 物理机:VMware 虚拟机 + CentOS 7.8 ...
- CLISP学习(二)
它是一门函数式语言,你要用函数的思维来思考. 只不过与数学的表达不同的是,数学里的函数是在括号外 f(x) ,而lisp是在括号内,以列表的形式(f x), cos(x) --> (cos x ...
- MongoDB分片副本集生产环境部署-Windows版本
title: MongoDB分片副本集生产环境部署(Windows版本) date: 2022-10-29 17:21:11 tags: - 运维 系统架构 配置环境 系统都是windows 10 专 ...
- 安装部署Java项目
开头:之前做了个文档转换的小项目,想部署在安卓手机上,自己可以随时看看,所以才有了下面这篇文章,内容或有瑕疵,望请批正.文末放我自己部署文档转换网址,仅供大家参考,谢谢! 选择:Termux 还是 L ...