@@ -1109,6 +1109,105 @@ CREATE OR REPLACE VIEW public.json_array_subquery_view AS
1109
1109
FROM ( SELECT foo.i
1110
1110
FROM ( VALUES (1), (2), (NULL::integer), (4)) foo(i)) q(a)) AS "json_array"
1111
1111
DROP VIEW json_array_subquery_view;
1112
+ create type comp1 as (a int, b date);
1113
+ create domain d2 as comp1;
1114
+ create domain mydomain as timestamptz;
1115
+ create type mydomainrange as range(subtype=mydomain);
1116
+ create type comp3 as (a int, b mydomainrange);
1117
+ create table t1(a text[], b timestamp, c timestamptz, d date,
1118
+ f1 comp1[], f2 timestamp[],
1119
+ f3 d2[], f4 mydomainrange[], f5 comp3);
1120
+ --JSON_OBJECTAGG, JSON_ARRAYAGG is aggregate function, can not be used in index
1121
+ create index xx on t1(JSON_OBJECTAGG(a: b ABSENT ON NULL WITH UNIQUE KEYS RETURNING jsonb));
1122
+ ERROR: aggregate functions are not allowed in index expressions
1123
+ LINE 1: create index xx on t1(JSON_OBJECTAGG(a: b ABSENT ON NULL WIT...
1124
+ ^
1125
+ create index xx on t1(JSON_OBJECTAGG(a: b ABSENT ON NULL WITH UNIQUE KEYS RETURNING json));
1126
+ ERROR: aggregate functions are not allowed in index expressions
1127
+ LINE 1: create index xx on t1(JSON_OBJECTAGG(a: b ABSENT ON NULL WIT...
1128
+ ^
1129
+ create index xx on t1(JSON_ARRAYAGG(a RETURNING jsonb));
1130
+ ERROR: aggregate functions are not allowed in index expressions
1131
+ LINE 1: create index xx on t1(JSON_ARRAYAGG(a RETURNING jsonb));
1132
+ ^
1133
+ create index xx on t1(JSON_ARRAYAGG(a RETURNING json));
1134
+ ERROR: aggregate functions are not allowed in index expressions
1135
+ LINE 1: create index xx on t1(JSON_ARRAYAGG(a RETURNING json));
1136
+ ^
1137
+ -- jsonb: create expression index via json_array
1138
+ create index on t1(json_array(a returning jsonb)); --ok
1139
+ create index on t1(json_array(b returning jsonb)); --error
1140
+ ERROR: functions in index expression must be marked IMMUTABLE
1141
+ create index on t1(json_array(c returning jsonb)); --error
1142
+ ERROR: functions in index expression must be marked IMMUTABLE
1143
+ create index on t1(json_array(d returning jsonb)); --error
1144
+ ERROR: functions in index expression must be marked IMMUTABLE
1145
+ create index on t1(json_array(f1 returning jsonb)); --error
1146
+ ERROR: functions in index expression must be marked IMMUTABLE
1147
+ create index on t1(json_array(f2 returning jsonb)); --error
1148
+ ERROR: functions in index expression must be marked IMMUTABLE
1149
+ create index on t1(json_array(f3 returning jsonb)); --error
1150
+ ERROR: functions in index expression must be marked IMMUTABLE
1151
+ create index on t1(json_array(f4 returning jsonb)); --error
1152
+ ERROR: functions in index expression must be marked IMMUTABLE
1153
+ create index on t1(json_array(f5 returning jsonb)); --error
1154
+ ERROR: functions in index expression must be marked IMMUTABLE
1155
+ --jsonb: create expression index via json_object
1156
+ create index on t1(json_object('hello' value a returning jsonb)); --ok
1157
+ create index on t1(json_object('hello' value b returning jsonb)); --error
1158
+ ERROR: functions in index expression must be marked IMMUTABLE
1159
+ create index on t1(json_object('hello' value c returning jsonb)); --error
1160
+ ERROR: functions in index expression must be marked IMMUTABLE
1161
+ create index on t1(json_object('hello' value d returning jsonb)); --error
1162
+ ERROR: functions in index expression must be marked IMMUTABLE
1163
+ create index on t1(json_object('hello' value f1 returning jsonb)); --error
1164
+ ERROR: functions in index expression must be marked IMMUTABLE
1165
+ create index on t1(json_object('hello' value f2 returning jsonb)); --error
1166
+ ERROR: functions in index expression must be marked IMMUTABLE
1167
+ create index on t1(json_object('hello' value f3 returning jsonb)); --error
1168
+ ERROR: functions in index expression must be marked IMMUTABLE
1169
+ create index on t1(json_object('hello' value f4 returning jsonb)); --error
1170
+ ERROR: functions in index expression must be marked IMMUTABLE
1171
+ create index on t1(json_object('hello' value f5 returning jsonb)); --error
1172
+ ERROR: functions in index expression must be marked IMMUTABLE
1173
+ -- data type json don't have default operator class for access method "btree" so
1174
+ -- we use a generated column to test whether the JSON_ARRAY expression is
1175
+ -- immutable
1176
+ alter table t1 add column f10 json generated always as (json_array(a returning json)); --ok
1177
+ alter table t1 add column f11 json generated always as (json_array(b returning json)); --error
1178
+ ERROR: generation expression is not immutable
1179
+ alter table t1 add column f11 json generated always as (json_array(c returning json)); --error
1180
+ ERROR: generation expression is not immutable
1181
+ alter table t1 add column f11 json generated always as (json_array(d returning json)); --error
1182
+ ERROR: generation expression is not immutable
1183
+ alter table t1 add column f11 json generated always as (json_array(f1 returning json)); --error
1184
+ ERROR: generation expression is not immutable
1185
+ alter table t1 add column f11 json generated always as (json_array(f2 returning json)); --error
1186
+ ERROR: generation expression is not immutable
1187
+ alter table t1 add column f11 json generated always as (json_array(f4 returning json)); --error
1188
+ ERROR: generation expression is not immutable
1189
+ alter table t1 add column f11 json generated always as (json_array(f5 returning json)); --error
1190
+ ERROR: generation expression is not immutable
1191
+ -- data type json don't have default operator class for access method "btree" so
1192
+ -- we use a generated column to test whether the JSON_OBJECT expression is
1193
+ -- immutable
1194
+ alter table t1 add column f11 json generated always as (json_object('hello' value a returning json)); --ok
1195
+ alter table t1 add column f12 json generated always as (json_object('hello' value b returning json)); --error
1196
+ ERROR: generation expression is not immutable
1197
+ alter table t1 add column f12 json generated always as (json_object('hello' value c returning json)); --error
1198
+ ERROR: generation expression is not immutable
1199
+ alter table t1 add column f12 json generated always as (json_object('hello' value d returning json)); --error
1200
+ ERROR: generation expression is not immutable
1201
+ alter table t1 add column f12 json generated always as (json_object('hello' value f1 returning json)); --error
1202
+ ERROR: generation expression is not immutable
1203
+ alter table t1 add column f12 json generated always as (json_object('hello' value f2 returning json)); --error
1204
+ ERROR: generation expression is not immutable
1205
+ alter table t1 add column f12 json generated always as (json_object('hello' value f3 returning json)); --error
1206
+ ERROR: generation expression is not immutable
1207
+ alter table t1 add column f12 json generated always as (json_object('hello' value f4 returning json)); --error
1208
+ ERROR: generation expression is not immutable
1209
+ alter table t1 add column f12 json generated always as (json_object('hello' value f5 returning json)); --error
1210
+ ERROR: generation expression is not immutable
1112
1211
-- IS JSON predicate
1113
1212
SELECT NULL IS JSON;
1114
1213
?column?
0 commit comments