I've been playing with Postgres for a week or so and I'm seeing if it's possible to set the min/max values for a sequence using an expression. The specific goal is to automate create-scripts for disjoint ranges between servers to avoid key-conflicts in a multi-master setup.
For example, using psql:
CREATE SEQUENCE key_seq MINVALUE (:servernum * :stride)
MAXVALUE ((:servernum + 1) * :stride - 1);
This gives me a syntax error. Variables are interpoaltedinterpolated verbatim, no calculations happenshappen.
An alternative would be to set a variable based on the output of an expression:
\set minvalue (:servernum * :stride)
But the \set
statement doesn't evaluate expressions.