On 2018/04/11 10:44, Tom Lane wrote: > Kyotaro HORIGUCHI <horiguchi.kyot...@lab.ntt.co.jp> writes: >> At least partition bound *must* be a constant. Any expression >> that can be reduced to a constant at parse time ought to be >> accepted but must not be accepted if not. > > My point is that *any* expression can be reduced to a constant, > we just have to do so.
Currently transformPartitionBoundValue() applies eval_const_expressions() by way of calling expression_planner(). However passing to it, say, an expression representing random() is unable to reduce it to a Const because simplify_function/evaluate_function won't compute a mutable function like random(). So, that currently results in an error like this (note that this is after applying Horiguchi-san's latest patch that enables specifying random() as a partition bound in the first place): create table foo_part partition of foo for values in ((random())::int); ERROR: specified value cannot be cast to type integer for column "a" LINE 1: ...table foo_random partition of foo for values in ((random()):... ^ DETAIL: The cast requires a non-immutable conversion. HINT: Try putting the literal value in single quotes. The error is output after the following if check in transformPartitionBoundValue fails: /* Fail if we don't have a constant (i.e., non-immutable coercion) */ if (!IsA(value, Const)) I think what Tom is proposing here, instead of bailing out upon eval_const_expressions() failing to simplify the input expression to a Const, is to *invoke the executor* to evaluate the expression, like the optimizer does in evaluate_expr, and cook up a Const with whatever comes out to store it into the catalog (that is, in relpartbound). Thanks, Amit