sqlpostgresqldatabase-partitioning

Postgres partition by range from x and above condition


I am wondering how to partition a table like,

CREATE TABLE grade_main 
(
    id serial not null, 
    g int not null
) partition by range (g);

CREATE TABLE grade_00_100 PARTITION OF grade_main FOR VALUES FROM (0) TO (100);
CREATE TABLE grade_100_200 PARTITION OF grade_main FOR VALUES FROM (100) TO (200);

-- The following returns syntax error

CREATE TABLE grade_150_all PARTITION OF grade_main FOR VALUES FROM (150);

Solution

  • To soecify a range that has no upper limit, use

    FOR VALUES FROM (150) TO (MAXVALUE)