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
随机推荐
- 使用Java刷评论为平台引流的经历
场景:需要在一网站中批量评论留言. 分析接口: 列表接口获取idList,返回的是json数据直接用FastJson转就可以,如果返回的是HTML片段,则需要使用Jsoup进行提取,值得一学,常用于爬 ...
- Typora快捷键--实用
一.字体编辑 大小:ctr + 数字 或 ctr + 加减号 或 ### 加粗:ctr + b 倾斜:ctr + i 下划线:ctr + u 删除线:alt + shift + 5 上标:^ + 字体 ...
- xxl-job定时调度任务Java代码分析
简介 用xxl-job做后台任务管理, 主要是快速解决定时任务的HA问题, 项目代码量不大, 功能精简, 没有特殊依赖. 因为产品中用到了这个项目, 上午花了点时间研究了一下运行机制. 把看到的记一下 ...
- Cryptohack的Adrien's Signs解题思路
题目如下: 输出的结果: 题目分析: 在原题的题目描述中并没有什么有用的消息,更多的信息是通过代码审计出来的.大致意思是,先把字节flag转换为二进制形式的字符串,然后判断字符串中每个字符,如果为1, ...
- DFS深度优先搜索例题分析
洛谷P1596 Lake Counting S 题面翻译 由于近期的降雨,雨水汇集在农民约翰的田地不同的地方.我们用一个 \(N\times M(1\times N\times 100, 1\leq ...
- .NET周报【12月第3期 2022-12-23】
由于众所周知的原因,大佬们纷纷加入羊群,笔者也未能幸免,体验下来这绝对不是普通感冒的症状,身体不适,熬了几天,所以本周更新比较晚:另外精力有限,对于国际板块只有链接没有简介,十分抱歉! 在这个艰难时刻 ...
- C++11(列表初始化+变量类型推导+类型转换+左右值概念、引用+完美转发和万能应用+定位new+可变参数模板+emplace接口)
列表初始化 用法 在C++98中,{}只能够对数组元素进行统一的列表初始化,但是对应自定义类型,无法使用{}进行初始化,如下所示: // 数组类型 int arr1[] = { 1,2,3,4 }; ...
- netcore下死RabbitMQ队列、死信队列、延时队列及小应用
关于安装rabbitmq这里一笔掠过了. 下面进入正题: 1.新建aspnetcorewebapi空项目,NormalQueue,删除controllers文件夹已经无关的文件,这里为了偷懒不用con ...
- 【项目实战】从零到一搭建Spring Boot整合Mybatis-plus
前言 2023年想搭建一套属于自己的框架,做一个属于自己想法的项目.这些年工作中一直用公司已有的框架,以前有跟着学习视频搭建过,但自己真正动手搭建时发现问题还是很多,比如没有引入Mybatis-plu ...
- vue中wowjs的使用
笔者亲测,在vue中使用wow.js如果不按照以下方法实施,会出现意想不到的BUG,网页刷新后图片就全部突然看不到了,被增加了一个隐藏属性,建议大家严格按照方法执行,不要随意使用 (1)通过npm安装 ...