@@ -27,8 +27,20 @@ SELECT COUNT(*) FROM test_exprs.hash_rel;
27
27
5
28
28
(1 row)
29
29
30
+ /* Try using constant expression */
31
+ SELECT create_hash_partitions('test_exprs.hash_rel', '1 + 1', 4);
32
+ ERROR: partitioning expression should reference table "hash_rel"
33
+ \set VERBOSITY default
34
+ /* Try using mutable expression */
30
35
SELECT create_hash_partitions('test_exprs.hash_rel', 'random()', 4);
31
- ERROR: functions in partitioning expression must be marked IMMUTABLE
36
+ ERROR: failed to analyze partitioning expression (random())
37
+ DETAIL: functions in partitioning expression must be marked IMMUTABLE
38
+ CONTEXT: SQL statement "SELECT public.validate_expression(parent_relid, expression)"
39
+ PL/pgSQL function prepare_for_partitioning(regclass,text,boolean) line 9 at PERFORM
40
+ SQL statement "SELECT public.prepare_for_partitioning(parent_relid,
41
+ expression,
42
+ partition_data)"
43
+ PL/pgSQL function create_hash_partitions(regclass,text,integer,boolean,text[],text[]) line 4 at PERFORM
32
44
/* Check that 'pathman_hooks_enabled' is true (1 partition in plan) */
33
45
EXPLAIN (COSTS OFF) INSERT INTO test_exprs.canary_copy
34
46
SELECT * FROM test_exprs.canary WHERE val = 1;
@@ -40,7 +52,7 @@ SELECT * FROM test_exprs.canary WHERE val = 1;
40
52
Filter: (val = 1)
41
53
(4 rows)
42
54
43
- \set VERBOSITY default
55
+ /* Try using missing columns */
44
56
SELECT create_hash_partitions('test_exprs.hash_rel', 'value * value2))', 4);
45
57
ERROR: failed to parse partitioning expression (value * value2)))
46
58
DETAIL: syntax error at or near ")"
@@ -132,10 +144,36 @@ EXPLAIN (COSTS OFF) SELECT * FROM test_exprs.hash_rel WHERE (value * value2) = 5
132
144
CREATE TABLE test_exprs.range_rel (id SERIAL PRIMARY KEY, dt TIMESTAMP, txt TEXT);
133
145
INSERT INTO test_exprs.range_rel (dt, txt)
134
146
SELECT g, md5(g::TEXT) FROM generate_series('2015-01-01', '2020-04-30', '1 month'::interval) as g;
135
- SELECT create_range_partitions('test_exprs.range_rel', 'RANDOM()', '15 years'::INTERVAL, '1 year'::INTERVAL, 10);
136
- ERROR: functions in partitioning expression must be marked IMMUTABLE
147
+ /* Try using constant expression */
148
+ SELECT create_range_partitions('test_exprs.range_rel', '''16 years''::interval',
149
+ '15 years'::INTERVAL, '1 year'::INTERVAL, 10);
150
+ ERROR: partitioning expression should reference table "range_rel"
151
+ \set VERBOSITY default
152
+ /* Try using mutable expression */
153
+ SELECT create_range_partitions('test_exprs.range_rel', 'RANDOM()',
154
+ '15 years'::INTERVAL, '1 year'::INTERVAL, 10);
155
+ ERROR: failed to analyze partitioning expression (RANDOM())
156
+ DETAIL: functions in partitioning expression must be marked IMMUTABLE
157
+ CONTEXT: SQL statement "SELECT public.validate_expression(parent_relid, expression)"
158
+ PL/pgSQL function prepare_for_partitioning(regclass,text,boolean) line 9 at PERFORM
159
+ SQL statement "SELECT public.prepare_for_partitioning(parent_relid,
160
+ expression,
161
+ partition_data)"
162
+ PL/pgSQL function create_range_partitions(regclass,text,anyelement,interval,integer,boolean) line 12 at PERFORM
163
+ /* Check that 'pathman_hooks_enabled' is true (1 partition in plan) */
164
+ EXPLAIN (COSTS OFF) INSERT INTO test_exprs.canary_copy
165
+ SELECT * FROM test_exprs.canary WHERE val = 1;
166
+ QUERY PLAN
167
+ ----------------------------------
168
+ Insert on canary_copy
169
+ -> Append
170
+ -> Seq Scan on canary_0
171
+ Filter: (val = 1)
172
+ (4 rows)
173
+
174
+ \set VERBOSITY terse
137
175
SELECT create_range_partitions('test_exprs.range_rel', 'AGE(dt, ''2000-01-01''::DATE)',
138
- '15 years'::INTERVAL, '1 year'::INTERVAL, 10);
176
+ '15 years'::INTERVAL, '1 year'::INTERVAL, 10);
139
177
create_range_partitions
140
178
-------------------------
141
179
10
0 commit comments