5

Actually I am new to PostgreSQL. I want to alter existing partition to increase range value. For example I have below partition

PQR_271 FOR VALUES FROM ('260000000') TO ('270000000')

Here I want to extend the range to max value but I am not able to do the same.

I tried below solution

CREATE TABLE public.PQR_272 PARTITION OF public.stats_to_institution FOR VALUES FROM ('270000000') TO ('280000000');
ALTER TABLE public.PQR_272 OWNER to usr_replica;

Here I can increase the integer value but I cannot increase to maxvalue. Is there any solution to set range to maxvalue?

PostgreSQL version11

6
  • 2
    I have never done this, but looking at the manual I would assume you need to detach the partition, then re-attach it with the new partition bounds Commented Oct 21, 2021 at 5:55
  • @a_horse_with_no_name it will delete the data too. Commented Oct 21, 2021 at 6:10
  • No, detaching a partition does not delete the data Commented Oct 21, 2021 at 6:20
  • @a_horse_with_no_name It did, I tried. Commented Oct 21, 2021 at 6:26
  • It works just fine: dbfiddle.uk/… Commented Oct 21, 2021 at 6:28

1 Answer 1

15

You can't alter the definition of a partition, but you can re-attach it with a different definition.

alter table stats_to_institution detach partition pqr_272;
alter table stats_to_institution attach partition pqr_272 
  for values FROM ('270000000') TO ('300000000'); --<< new upper bound

Obviously the data in that partition won't be visible in the main table between the detach and attach operation, but the data is still there.

Online example

Sign up to request clarification or add additional context in comments.

1 Comment

thats for the solution. Even this query worked for me. CREATE TABLE others PARTITION OF pqr FOR VALUES FROM ('280000000') TO (MAXVALUE);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.