When an error is reported when creating a functional index, the error information is the title, and the following is the details.
Table 1 Definition
1 |
skytf=> \d test_39; |
Now you need to create a federated index on the fields “skyid”, “create_time”.
2 create index
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” means that the function must be marked as “immutable” when creating a function index.
3 view to_ Char function
1 |
skytf=> \df to_char(); |
4. Connect with Postgres super user and modify to_ Char function properties
1 |
skytf=# alter function to_char(timestamp with time zone, text) IMMUTABLE; |
Note: due to table test_ Column create on 39_ The time type is “timestamp with time zone”, so the function to should be modified when modifying the function_ Char (timestamp with time zone, text). For your own safety, do not modify to directly_ Char function. It is recommended to create a to of immutable attribute_ char_ Immutable function.
5 validation
1 |
skytf=> \ef to_char(timestamp with time zone, text) |
As can be seen from “immutable strict”, the function has been modified to “immutable” attribute.
6 connect with skytf and create the index again
1 |
skytf=> create index CONCURRENTLY idx_test_skyid_ctime on test_39 using btree (skyid, to_char(create_time, 'YYYY-MM-DD') ); |
Note: when modifying function to_ After the char (timestamp with time zone, text) attribute, the index is created successfully.
1 |
skytf=> \d test_39 |
7 explanation of “immutable” attribute in the manual
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 summary
the default attribute of the function is “Volatile”, which can be changed. When creating a function index, you need to change the attribute of the reference function to “immutable”, that is, stable, and the function index can be created successfully. That is, only functions with stable attributes can be used to create functional indexes.
Similar Posts:
- Greenplum Error: query plan with multiple segworker groups is not supported
- When mysql creates a table, set timestamp DEFAULT NULL error 1067-Invalid default value for’updated_at’
- Get the time value from the database and report an error: Java sql. Timestamp cannot be cast to java. lang.Long
- MYSQL ERROR 1005 (HY000): Can’t create table [How to Solve]
- Kingbasees supports column encryption
- MySQL timestamp set default value error Invalid default value reason and solution
- Failed to obtain JDBC Connection
- Springboot uses the Datetimeformat (pattern = “yyyy MM DD HH: mm: SS”) annotation to automatically convert the string to date type error
- MySQL: invisible empty symbol char (9) char (10) char (13)
- [Solved] cannot load from mysql.proc. the table is probably corrupted