From: Laurenz Albe <laurenz.albe@cybertec.at>
To: Oliver Urones <ourones.joinup@gmail.com>
To: pgsql-admin@lists.postgresql.org
Subject: Re: Partition table with a foreign key self-reference
Date: Wed, 05 Feb 2025 08:18:02 +0100
Message-ID: <cbad2d1e795179b28ef82d021839ef15e56db93c.camel@cybertec.at> (raw)
In-Reply-To: <CAH2eNKX7wg7mZYr6jt4c6iZey6HYQUY-3DLPJMT3wWqy1gNFmg@mail.gmail.com>
References: <CAH2eNKX7wg7mZYr6jt4c6iZey6HYQUY-3DLPJMT3wWqy1gNFmg@mail.gmail.com>
On Tue, 2025-02-04 at 16:57 +0100, Oliver Urones wrote:
> I need help with the process of partitioning tables.
>
> How can I partition a table that has a foreign key that references itself?
>
> Something like this example:
>
> CREATE TABLE employees (
> employee_id SERIAL PRIMARY KEY,
> name VARCHAR(50),
> boss_id INTEGER,
> CONSTRAINT fk_boss FOREIGN KEY (boss_id) REFERENCES employees(employee_id)
> );
>
> I'm using Postgresql 14.
The question makes no sense as such. You'd have to tell us the purpose
you want to achieve with partitioning. Depending on that, you'd choose
the partitioning strategy and the partitioning key.
At any rate, you'll probably have to drop the foreign key constraint
unless your partitioning key is "id".
Yours,
Laurenz Albe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-admin@postgresql.org
Cc: laurenz.albe@cybertec.at, ourones.joinup@gmail.com, pgsql-admin@lists.postgresql.org
Subject: Re: Partition table with a foreign key self-reference
In-Reply-To: <cbad2d1e795179b28ef82d021839ef15e56db93c.camel@cybertec.at>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox