0

I have table which is contained list partition in postgres database

create table test(id int, name character varying) partition by list(id);

when I insert data, it is throwing an error.

insert into test values(1,'test1'),(2,'test2')
ERROR: Partition key of the failing row contains (id) = (1).no partition of relation "test" found for row

Note: as now I cannot predefine what are the id's can insert

Based on the id's inserted on table, postgres tables needs to partitioned automatically

Greg
6,7911 gold badge29 silver badges61 bronze badges
asked Oct 9, 2024 at 7:03
2
  • See Automating partitions creation in Postgres 10. Commented Oct 9, 2024 at 9:34
  • id int tells me that the maximum number for the id will be 2147483647. How many records do you expect and how many partitions do you want? Pick an answer and create your partitions. Commented Oct 9, 2024 at 13:04

1 Answer 1

0

PostgreSQL will not create partition tables automatically for you, this is something you need to either create ahead of time, or create new partitions when the need arises.

Please refer to the step-by-step example: https://www.postgresql.org/docs/current/ddl-partitioning.html#DDL-PARTITIONING-DECLARATIVE-EXAMPLE

answered Oct 9, 2024 at 9:24
Sign up to request clarification or add additional context in comments.

2 Comments

is the same requirement achievable using pg_cron jobs? if yes how it is
It depends how you partition your data. If you partitioned it by some date field (say one partition per day), I would imagine you could have a cron that creates a new partition table for the next day. But this is a whole new queston – feel free to submit a new one.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.